• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

When does the hibernate query commit?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will session.save(customer); do any checking on the database? If there is a primary key violation will an exception be thrown while saving the object?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Absolutely. It will just throw any SQLExceptions generated by violating and constraints you have imposed on your data.
 
dina raj
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use session.save(customer);
My problem is that ,
Now my custonmer table has a child CUST_IDEN. The statement
session.save(customer);
does not throw any exception if there is a primary key violation in CUST_IDEN table. Instead the exception is thrown only later when i commit the transaction.
Is this how it is supposed to happen?
The CUSTOMER hbm file contains this entry which relates it to the CUST_IDEN table
<set name="identifiers" cascade="all-delete-orphan" inverse="true" lazy="true" table="CUST_IDEN">
<key column="CUST_ID" update="true" not-null="true" />
<one-to-many class="CustomerIdentifier"/>
</set>
 
ranger
Posts: 17347
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, since session.save() does not go to the database immediately. Only when you commit, or if you were to run a query on that table that makes Hibernate do a flush on the session and calls the database.

This is to increase performance. It is also why you want to open and commit a session as quickly as possible, so the "transaction/session" demarcation is very short, if you do a lot of work, you could face issues like what you are having an issue with.

Mark
reply
    Bookmark Topic Watch Topic
  • New Topic