• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Inverse Attribute : Serious Problem

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that the code is as in the book, are you using the same version of Hibernate?
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic