Atitit. atitit. hb many2one relate hibernate multi-to-one association configuration..., hibernate configuration file
Atitit. atitit. hb many2one relate hibernate multi-to-one association configuration ..
1. Many-to-one @ ManyToOne 1
1. @ JoinColumn annotation 2
2. @ targetEntity annotation 2
2. generated SQL LEFT OUTER 2
3. Multiple-to-one can also be mapped by associating tables. The @ JoinTable annotation can be set to 2.
4. Another attribute is also associated with table column (recomn ?? ) 3
5. Reference 3
1. Many-to-one @ ManyToOne
(For database design, foreign keys are mostly designed in multiple parties)
Database Design: Primary Key Columns cannot be divided, and the joint primary key cannot have partial dependencies and cannot have transmission dependencies.
Add a "one-party" class to the Multi-Party class in the annotation, and add @ ManyToOne to the get method.
Author: old wow's paw Attilax iron, EMAIL: 1466519819@qq.com
Reprinted please indicate Source: http://blog.csdn.net/attilax
· @ ManyToOne (cascade = {CascadeType. PERSIST, CascadeType. MERGE}, targetEntity = CompanyImpl. class)
· @ JoinColumn (name = "COMP_ID ")
· Public Company getCompany (){
· Return company;
·}
·...
·
1. @ JoinColumn Annotation
· Optional. The default value of a keyword field is similar to that of a one-to-one association. The column name is: Association attribute name of the topic + underline + primary key column name of the associated end. In this example, company_id is used, because the associated property is company, and the primary key of Company is id.
· Creator_ID % attribute name % _ primary key column name (not cls property name)
· If coc is not available, set this annotation.
·
2. @ targetEntity Annotation
· There Is A targetEntity attribute, which defines the target object name. Generally, no definition is required. In most cases, the default value is used. In this case, the targetEntity definition is required (using an interface as the return value, rather than a common entity ).
·...
·
2. generated SQL LEFT OUTER
FROM
Gv_material gvmaterial0 _
Left outer join t_user_users tusers1 _ ON gvmaterial0 _. create_user = tuserusers1 _. ID
3. You can also map multiple pairs by associating tables. The @ JoinTable annotation works.
· Define the joined table. The associated table contains the foreign key (via @ JoinTable. joinColumns) that refers to the object and the foreign key pointing to the target object table (via @ JoinTable. inverseJoinColumns ).
·
· @ Entity ()
· Public class Flight implements Serializable {
·
· @ ManyToOne (cascade = {CascadeType. PERSIST, CascadeType. MERGE })
· @ JoinTable (name = "Flight_Company ",
· JoinColumns = @ JoinColumn (name = "FLIGHT_ID "),
· InverseJoinColumns = @ JoinColumn (name = "COMP_ID ")
·)
· Public Company getCompany (){
· Return company;
·}
·...
·}
·
4. Another attribute is also associated with table column (recomn ?? )
Jonjye nen single test l...
Insertable = false: The foreign key column does not appear in the INSERT statement.
Updatable = false: The foreign key column does not appear in the UPDATE statement.
The most common use case is that another attribute in this class is directly associated with a foreign key:
@ Column (name = "USER_ID ")
Long user_id;
@ Onetoworkflow
@ JoinColumn (name = "USER_ID", insertable = false, updatable = false)
User user;
5. Reference
Hibernate annotation-java-iteyetechnical website .htm
Use hibernateinjection to configure three unique _ saminar2012_sina blog .htm