Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cascade operations only populate foreign key for the owning side of the relationship

 
Odair Brentam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Helo, I have two entities with the following mappings


When this method completes Q1 and A1 are persistes but the foreign key IS NULL
but for A2 and Q2 the foreign key is INSERTED WITH THE CORRECT VALUE.

The point is: the foreign key is filled only if the entity passed to the persit() is an "owning side" entity.

Is it not possible to use the cascade operations when persisting a entity of the "inverse side" of the relationship and have the foreign key populated?
[ June 21, 2008: Message edited by: Odair Brentam ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Brentam", please check your private messages for an important administrative matter.

Also, please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JPA you must maintain bi-directional relationship in your application or object mode code. Basically you code should work if you set methods also set the inverse relationship (careful of the infinite loop).

see,
http://en.wikibooks.org/wiki/Java_Persistence/Relationships
> One side of the relationship is not updated after updating the other side
 
Odair Brentam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry about the unformatted code,
thanks james.
[ June 21, 2008: Message edited by: Odair Brentam ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic