-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Annotations - How to override Identifier
PostPosted: Wed Jan 09, 2013 2:09 pm 
Newbie

Joined: Wed Jan 09, 2013 1:50 pm
Posts: 1
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.