Hibernate annotation relational mappings, cascading cascade Properties
One. Hibernate Annotation Relationship Mapping
1. One-way foreign key correlation mapping (unidirectional)
2. One-to-one foreign key correlation mapping (bidirectional)
3, one-to-one primary key association mappings (not important) in this does not show
Rarely used in practice, use annotations @primarykeyjoincolumn
It means that my primary key is to refer to the primary key in the other table as my primary key, but in my test use
Note a one-to-one primary key association mapping, when generating a table, does not generate an association in the database, using XML
Mappings can be generated. annotation annotation one-to-one primary key correlation mapping, some bugs. But there is no time to study it.
Because it's rarely used in real-world development. In actual development I had no chance to use it, and the primary key association was even less.
4, many-to-one correlation mapping
5, one-to-many correlation mapping (unidirectional)
6, one-to-many correlation mapping (bidirectional)
7, many-to-many correlation mapping (unidirectional)
8, many-to-many association mappings (bidirectional)
Two. Other configurations
Cascading (Cascade) Properties
1, Cascadetype.all (including increase, delete, change, check, linkage operation), in fact, do not count, check fetch
2. Cascadetype.merge (merged join)--not important
3, Cascadetype.persist (when saving in cascade)
4, Cascadetype.refresh (Refresh Description: For example, now I query out the data, another person in my query data, he made changes to the data, this is only cascade, Hibernate will automatically refresh my query out of the data)
5, Cascadetype.remove (as long as the delete operation will not cascade)
6, we generally only set cascadetype.all on OK,
7, Cascade is not necessary, his role is only allows us to develop quickly, we can also manually increase, delete, change, check
Fetch capture Strategy
1, Fetchtype.eager (eager, hope to get it right away)
A) a one-to-many relationship, such as a Get () method to get out of a side, he will be out of a SQL statement, will not automatically go to query the end of the many, if set Fetchtype.eager, will tell his associated object query out
b) If it is load, he will not issue the SQL statement because load supports lazy loading, and only SQL is sent when the data is actually fetched
2. Fetchtype.lazy (Lazy Loading)
A) The SQL statement is issued only when the data is actually obtained
3, the default is: Fetchtype.lazy (one-to-many)
4, the default is: Fetchtype.eager (many to one)
5, the general use of the default will be
Hibernate annotation relational mappings, cascading cascade Properties