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

hibernate problem with saveOrUpdate

 
Andrew Cane
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As of now, I have :



and


1. When I ran saveOrUpdate, hibernate updated several fields in country table (as expected), but what I can't understand is how hibernate updated states owned by the country (I added one new state). First, it set existing states' country_code to null, and inserted the new state and finally set the country_code of the new state as my input, leaving the previously existing states' country_code to null, so now the country only has one state. How do I fix this? what should I add to the classes?
2. Also, I noticed hibernate's behavior that it won't insert the foreign key of child rows during insertion. hibernate always inserts the child rows, and then issue an update statement to fill the FK fields. Is there anyway for me to tell hibernate to fill the FK fields immediately since it's not something generated by DB, rather, it's manually entered by user. So, no need for extraneous update statements.
thanks
 
Andrew Cane
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what's the best practise in persisting objects with parent-child relationship? annotate the classes involved and simply calling session.save() or should we use HQL and construct the necessary HQL statements by hands?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic