-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Controlling Insert and Update Query ordering
PostPosted: Mon Apr 26, 2010 7:19 am 
Newbie

Joined: Sun Mar 22, 2009 5:20 am
Posts: 6
Consider the following association
Book has OneToMany Chapters

If i execute:

Code:
session.save(book)
session.save(chapter)
session.getTransaction().commit()


Hibernate generates insert query for Book and insert query for Chapter

But if i execute:

Code:
session.save(chapter)
session.save(book)
session.getTransaction().commit()


Hibernate executes insert query for chapter, insert query for book and update query for chapter.

Is there any way to do this in 2 inserts instead of 2 inserts and 1 update?
hibernate.order_inserts or hibernate.order_updates doesn't help.

[Assume Identity or equivalent primary key generation for Book and Chapter and provided Chapter.Book is nullable in this case]

If this is possible somehow:
I'm working on an app which reads version tables generated using triggers.
This app assumes that there will be only one operation: Insert/Update/Delete on each row in a transaction.
Is this a valid assumption in Hibernate? Is there any other scenario where this assumption is invalid?


Top
 Profile  
 
 Post subject: Re: Controlling Insert and Update Query ordering
PostPosted: Mon Apr 26, 2010 8:14 am 
Newbie

Joined: Sun Mar 22, 2009 5:20 am
Posts: 6
Even if Chapter.Book is not nullable in mapping and DB,
Hibernate expects Book to be saved first and Chapter next.

If done the other way, it fails with a NOTNULL constraint error in DB
Is this a bug or am i doing something wrong?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.