-->
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.  [ 2 posts ] 
Author Message
 Post subject: My first OneToMany link ?
PostPosted: Mon Feb 09, 2009 7:08 am 
Beginner
Beginner

Joined: Wed Jan 28, 2009 10:16 am
Posts: 37
Hello,

I try my first oneToMany link with this documentation, but the sample does not work ?

http://www.hibernate.org/hib_docs/annot ... ntity.html

I have juste a Person entity and I would like to join a lot a phone like this :

Code:

@Entity
class Person {

@Id
private int id;
...
@OneToMany(mappedBy="num")
   private List<Phone> phones;

..



@Entity
class Phone {
@Id
private String num;
...

I travel a lot of website but no one says the same thing ??


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2009 1:11 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
try adding the targetEntity

Code:
OneToMany(mappedBy="num" targetEntity="yourpackage.Phone.class"))


Also try specifying the table you are mapping to
Code:
@Entity
@Table (name="BR_RULE")


And finally other people might disagree but I usually instantiate all my collections. This way I don't have to deal with nulls later on.

Code:
@OneToMany(mappedBy="num" targetEntity="yourpackage.Phone.class"))
   private List<Phone> phones = new ArrayList<Phone>();


Are you receiving any exceptions if so please post the stack trace.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.