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: @OneToOne, bidirectional
PostPosted: Fri Dec 04, 2009 5:09 pm 
Beginner
Beginner

Joined: Wed Nov 12, 2008 12:07 pm
Posts: 21
Hello
I have a one-to-one bidirectional association, nullable.
So I made these annotations to my classes:
Code:
public class Boy {
...
   @OneToOne(cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
   @Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)   
   @JoinColumn(name="G_oid", referencedColumnName="oid", nullable=true)
   private Girl girl;
...
}


public class Girl {
...
   @OneToOne(mappedBy = "girl", cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
   @Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)   
   private Boy boy;
...
}


So I'm creating a girl and setting a boy for her that was already persisted, long time ago, in other session. When I persist the girl she goes to database but G_oid is not set. I thought that it would be updated. Am I doing something wrong?

Thank you


Top
 Profile  
 
 Post subject: Re: @OneToOne, bidirectional
PostPosted: Fri Dec 04, 2009 5:28 pm 
Beginner
Beginner

Joined: Wed Nov 12, 2008 12:07 pm
Posts: 21
Well, putting the join column on Girl class, mappedBy on Boy class and persinting the girl will fill the join column correctly but the thing is that I really want to leave the join column on Boy and persist the girl. Is it not possible?


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.