Skip to main content

2 Embedded of same class in one entity?

1 reply [Last post]
marlor
Offline
Joined: 2006-02-15
Points: 0

Hello

Here is the problem (simplified):
---------------------------------------------------
@Embeddable
class Version {
String vname;
....
}

@Entity
MyObject {
@Embedded
Version majorVersion;

@Embedded
Version minorVersion;
}
---------------------------------------------------

As you can guess the property names (such as 'vname') of the Version class clash because Version is embedded twice.

I know I can do a OneToMany etc etc way but that is not a preferred option. It is also not an option to create different version classes for minor and major. The classes I am writing JPA annotation on top are generated by JAXB from a XML schema and I need to keep those classes. Is there a way around this problem?

Thanks in advance

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
chris_delahunt
Offline
Joined: 2005-07-06
Points: 0

Hello,

Have you looked into @AttributeOverride?

@Entity
MyObject {
@Embedded
@AttributeOverride(name="vname", column=@Column(name="MAJOR_VNAME"))
Version majorVersion;

@Embedded
@AttributeOverride(name="vname", column=@Column(name="MINOR_VNAME"))
Version minorVersion;
}

Best Regards,
Chris