I'm working with Hibernate Annotations and the issue that I'm trying to solve goes as follows:
I need to have 2 different @Entity classes with the same columns mapping but with a different Identifier.
The first one should use id as identifier.
The second should use name as identifier.
So, I have an abstract class, annotated with @MappedSuperclass that have all of the columns including id and name, and in addition 2 @Entity classes that extends the super class and 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 in each class and it's not a good design :( In addition, the following insertable="false, updateable=false can help but i don't understand what is the meaning of this...
Please help me!