Read a book before, the introduction of hibernate in the time repeatedly stressed not easy to set a one-way relationship
The reason for the explanation in the book is that it affects performance (the resulting SQL statements become more).
one-way, many-to-1 Relationships
foreign Key dependency: by following the @ManytoOne @CasCade
First persist from the table records, and then persist the main table record: when the main table does not have a corresponding record, from the table waiting for the main table insert record and then insert (2 sql)
Connection Table:
There is no dependency on the two entity class tables, and the join table relies on the two entity class Tables. Two entity class table data which persisted first (no entity data is inserted to determine the wait process, but there are 3 SQL Statements---two entity class data persisted, join table information Inserted)
The book says that in this case, the connection table is better in this way . (for specific Reasons)
one-way, 1-to-many Relationships
Foreign Key dependency
cascading settings: found @onetomany can not keep up with the @CasCade (cascadetype.all), will Error. (maybe I set the wrong METHOD)
Do not set cascading: first persist from the table record, then persist the main table record: persist the record from the table but not set the foreign key value, and then persist the main Table record, update the foreign key value from the table that record (3 sql)
First persist the main table record, then persist from the table Record: first insert the main table record, and then insert the foreign key value from the table record but not set the foreign key value, then update the values from these records (3 sql)
Join Table: not discussed at this Stage.
A one-way, 1-to-many relationship always requires a single operation of N (in addition to using SQL directly in hibernate).
Although this is logically reasonable, it is really uncomfortable in the Program.
One-to-many relationships in Hibernate