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?