Hi,
I'm struggling with an Hibernate annotations issue several day without any findings, please help me with the following:
I need to have 2 different @Entity classes with the same columns mapping but with a different Identifier. (@id field)
The first one should use id field as identifier. The second should use name field as identifier.
I have an abstract class, annotated with @MappedSuperclass that have all of the columns including id and name, and in addition 2 @Entity sub classes that overriding the getters of the id and name.
@MappedSuperclass public class MappingBase { protected Integer id; protected String name;
@Column (name = "ID") public void getId() { return this.id; }
@Column (name = "NAME") public void getName() { return this.name; } }
@Entity @Table (name = "TABLE") public class Entity1 extends MappingBase {
@Id @Column (name = "ID") public void getId() { return this.id; } }
@Entity @Table (name = "TABLE") public class Entity2 extends MappingBase {
@Id @Column (name = "NAME") public void getName() { return this.name; } }
Note: I must have the members (id,name) in the super class.
I know that i can add @Transient to the id and name getters but this means that i must add both of them (id and name fields) in each class and it's not a good design :( In addition, in the exception that I'm getting it says to add the following insertable="false, updateable=false. it helps but i don't understand what is the meaning of this... and i don't think that it's the solution.
Please help me to understand if it's possible to implement.
Thanks!
|