emmanuel wrote:
1.
the reasons for you to use a unidirectional one to many should lead the DBA to agree that a join table is the appropriate solution. Otherwise your reasons were wrong.
A unidirectional one to many (with join column) is not as efficient as a bidirecdtional since it requirespotentiall an extra UPDATE that could have been mutualized witht the associated entoty update
Sorry for bringing up an old thread - but I'm struggling with the efficiency of a uni-directional one-to-many join. (Much like bennyboy here:
http://forum.hibernate.org/viewtopic.php?t=969402).
I've currently seen no explanation (questions on this seem sparse), as to why Hibernate uses an insert and then an update when persisting the children in the one-to-many.
In fact, it even seems from tracing hibernates SQL generation that mutualizing the update would be perfectly possible. Again, as per Benny Boy, I see this in my sql generation:
Code:
1) generate key for parent
2) insert parent
3) loop over children
4) generate key for child
5) insert child (with foreign key to parent = null)
6) update child to set parent foreign key reference
7) end loop
From the ordering of the above, its clear that the parent key (generated on line 1), and used on line 6, could quite equally be part of the initial insert on line 5.
In addition, inserting a null into the foreign key field (line 5), would in many database schema's violate a database constraint.
Explanations of why appreciated!
Jason
(Hibernate 3.2, sybase 12.5)