Results 1 to 2 of 2
Thread: JPA Inheritance
- 01-07-2011, 04:09 PM #1
Member
- Join Date
- Dec 2010
- Location
- Bucharest Romania
- Posts
- 40
- Rep Power
- 0
JPA Inheritance
Hi all,
i have some problems with JPA Inheritance.
i have one Entity named Person
and two other entities that extends Person (ClientPHP Code:@Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="personType",discriminatorType=DiscriminatorType.INTEGER) @Table(name="persons") public class Person implements Serializable{ /* normally i should have something like *private List<EmailAddress> emailAddresses; *private List<Phone> phones; * * setters and getters here */ ... bla bla bla ... }
and ContactPHP Code:@Entity @DiscriminatorValue("1") public class Client extends Person { ............................ }
). Each Person is in a OneToMany relationship with other two entities: Phone and EmailAddress.PHP Code:@Entity @DiscriminatorValue("0") public class Contact extends Person { private static final long serialVersionUID = 1L; .................................. }
Normally I should have inside Person class setters and getters for phone and emailAddress, but here i have encountered a problem.
Because my entities are mapped in a bidirectional relationship with eachother, so in Phone and EmailAddress i should have a getPerson() method. That is not right, because i needed there a method as getClient() or getContact(), and due that fact i have moved phones and emailAddresses variables (with getters and setters ) from Person to Client/Contact. Yet another problem here :)
In Phone and EmailAddress i have :
and when i compile i getPHP Code:@ManyToOne @JoinColumn(name="person_id") public Client getClient(){ return this.client; } public void setClient(Client c){ this.client = c; } @ManyToOne @JoinColumn(name="person_id") public Contact getContact(){ return this.contact; } public void setContact(Contact c){ this.contact = c; }
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: xxx.vs.common.hibernate.entities.virtual.EmailAddr ess column: person_id (should be mapped with insert="false" update="false")
I can fix this, but the question is : is this the appropriate way to achieve that ? Or i have to act somehow different ?
Thanks in advance.
- 01-10-2011, 06:44 AM #2
Member
- Join Date
- Dec 2010
- Location
- Bucharest Romania
- Posts
- 40
- Rep Power
- 0
Similar Threads
-
Inheritance
By terahawks in forum New To JavaReplies: 1Last Post: 04-23-2010, 09:58 AM -
Inheritance
By Nerijus in forum New To JavaReplies: 5Last Post: 04-20-2010, 03:47 AM -
Inheritance
By gpio in forum Advanced JavaReplies: 14Last Post: 11-20-2009, 10:41 AM -
Inheritance example
By kris4u4ever in forum New To JavaReplies: 3Last Post: 03-21-2009, 02:53 PM -
Inheritance in GUI
By Marty in forum SWT / JFaceReplies: 2Last Post: 05-11-2007, 12:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks