-->
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.  [ 5 posts ] 
Author Message
 Post subject: [Newbie question] OneToMany problem
PostPosted: Mon Jun 14, 2010 5:59 am 
Newbie

Joined: Sun Jun 13, 2010 5:08 pm
Posts: 4
I would like to build up a test case about OneToMany bidirectional object relation.
The modeled case is: people may have more phone number (phone * - > 1 person) (person 1 - > * phone)
As for my understanding the foreign column (cperson_id) belongs to the cphone_number
...................................... CPerson.java
@Entity
public class CPerson {
@Id @GeneratedValue
private Long Id;
private String Name;
@OneToMany(mappedBy="cperson")
private List<CPhoneNumber> PhoneNumbers;

...................................... CPhoneNumber.java
@Entity
public class CPhoneNumber {
@Id @GeneratedValue
private Long Id;
private String Number;

@ManyToOne @JoinColumn(name="cperson_id")
private CPerson Person;

Unfortunatelly I got this error:
mappedBy reference an unknown target entity property: hello.OneToMany.CPhoneNumber.cperson in hello.OneToMany.CPerson.PhoneNumbers


What did I wrong ?
Thanks in advance.

cscsaba

PS:
I have read through some chapter about JPA and Hibernate Entity relationship and both of them agree with the followings:
In case of bidirectional one to many relations we use
on the OneToMany role side the
- (mappedBy="x") where x is the name of counter side entity class in case of bidirectional relationship
on the ManyToOne
- JoinColumn wich refers to foreign column


Top
 Profile  
 
 Post subject: Re: [Newbie question] OneToMany problem
PostPosted: Mon Jun 14, 2010 6:15 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
- (mappedBy="x") where x is the name of counter side entity class in case of bidirectional relationship
on the ManyToOne


The name is the name of the variable (Person) not the name of the class (CPerson). @OneToMany(mappedBy="person") should work.


Top
 Profile  
 
 Post subject: Re: [Newbie question] OneToMany problem
PostPosted: Mon Jun 14, 2010 10:21 am 
Newbie

Joined: Sun Jun 13, 2010 5:08 pm
Posts: 4
nordborg wrote:
Quote:
- (mappedBy="x") where x is the name of counter side entity class in case of bidirectional relationship
on the ManyToOne


The name is the name of the variable (Person) not the name of the class (CPerson). @OneToMany(mappedBy="person") should work.



Unfortunately, It doesn't work :(, see the pic below.

http://imagebin.org/101280

Thank you for your effort.


Top
 Profile  
 
 Post subject: Re: [Newbie question] OneToMany problem
PostPosted: Mon Jun 14, 2010 10:58 am 
Newbie

Joined: Mon Jun 07, 2010 3:38 pm
Posts: 3
See that you have 'person' property starting with upper case.

Code:
@ManyToOne @JoinColumn(name="cperson_id")
private CPerson Person;


Top
 Profile  
 
 Post subject: Re: [Newbie question] OneToMany problem
PostPosted: Mon Jun 14, 2010 12:27 pm 
Newbie

Joined: Sun Jun 13, 2010 5:08 pm
Posts: 4
steppen wrote:
See that you have 'person' property starting with upper case.

Code:
@ManyToOne @JoinColumn(name="cperson_id")
private CPerson Person;


Thanks really, it works.

PS: It seems to be more strict with the java variables than column names I mean the case sensitivity.


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

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.