This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Object Relational Mapping and the fly likes JPA reference OneToOne CascadeType problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA reference OneToOne CascadeType problems " Watch "JPA reference OneToOne CascadeType problems " New topic
Author

JPA reference OneToOne CascadeType problems

Sergey Deplake
Greenhorn

Joined: Apr 13, 2010
Posts: 13
There are 2 tables in database and 2 entities according them. I make them easier.

Table 1 and entity:


Table 2 and entity:


Then I make 2 objects. First of the first entity, second of the second entity. Then set second object into first and persist first entity. In result first table fill in correctly, but in the second table appiars a problem. Field Table1Id contains null, but not id of the first entity. Why is it so? What can be the problem of this and how can I solve my problem?
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
You need to set both sides of the relationship.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Object_corruption.2C_one_side_of_the_relationship_is_not_updated_after_updating_the_other_side

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Sergey Deplake
Greenhorn

Joined: Apr 13, 2010
Posts: 13
Thank you for help. Now everything work correct!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA reference OneToOne CascadeType problems