Consider the following association book contains chapters of OneToMany
If I do:
session.save(book)
session.save(chapter)
session.getTransaction().commit()
Hibernate generates an insert request for a book and inserts a request for a chapter
But if I do:
session.save(chapter)
session.save(book)
session.getTransaction().commit()
Hibernate executes an insert request for a chapter, inserts a request for a book, and an update request for a chapter.
Is there a way to do this in 2 inserts instead of 2 inserts and 1 update? (Assume that primary key generation is similar to Identity and Chapter.Book cannot be zero)
source
share