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

Inverse Attribute : Serious Problem

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Example : Bid, Item

Item.hbm.xml :



NOTE: In Item.hbm.xml there isnt any inverse attribute .......

Bid.hbm.xml :


When i execute the following code :



The output is :
Hibernate: insert into ITEM (ITEM_NAME, ITEM_DESCRIPTION, ITEM_INITIAL_PRICE, ITEM_RESERVE_PRICE, ITEM_START_DATE, ITEM_END_DATE, ITEM_ID) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into BID (BID_AMOUNT, BID_CREATED_DATE, ITEM_ID) values (?, ?, ?)
Hibernate: update BID set ITEM_ID=? where BID_ID=?

According to "Hibernate In Action" book, it should execute 2 update statements (on same foreign key i.e ITEM_ID of BID table)
BUT Here it has execute only 1 update statement. WHY?
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that the code is as in the book, are you using the same version of Hibernate?
 
Rajan Nath
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had also gone through such scenario,if you add two bid (2 child object) then two insert and two update statement will execute, if one bid added then one insert and update statement will execute
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, when you call session.save and insert statement is sent to the database. If you change the object while still in the session and Hibernate managing it, then when you commit, it will run an update statement. That is fine and should be expected.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic