ATITIT.ATITIT.HB Many2one relate hibernate Many-to-one affinity configuration:

Source: Internet
Author: User

ATITIT.ATITIT.HB Many2one relate hibernate Many-to-one affinity configuration :

1. Many-to-one unidirectional @ManyToOne 1

1. note of @JoinColumn 2

2. @targetEntity Annotations 2

2. Generated SQL left OUTER 2

3. Many-to-one can also be mapped by association table, through the @JoinTable annotations can be 2

4. Another attribute is also associated to table column (recomn??) 3

5. Reference 3

1. Many-to-one unidirectional @ManyToOne

(Database design, many in the multi-design foreign key)

Database design: Primary key columns are not divided, the Federated primary key cannot be partially dependent, cannot exist transitive dependencies

A class that adds a "party" to a class in a multiparty, and then adds @manytoone on top of the Get method

Author:: Old Wow's paw attilax Ayron, email:[email protected]

Reprint 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. Where@JoinColumnAnnotations

· Is optional, the key field default value is similar to one-to-one correlation. Column name: The subject's associated property name + underscore + The primary key column name of the associated end. In this case, company_id, because the associated property is company, and the primary key for the IS ID.

· creator_id% attribute name%_ primary key column name (not CLS property name)

· If the COC is not possible, set this annotation.

·

2. @targetEntityAnnotations

· There is a Targetentity property that defines the target entity name. Definitions are usually not required, most of which are default values. The following scenario, however, requires a targetentity definition (using interfaces as return values rather than common entities).

· ...

·

2. Generated SQL Left OUTER

From

Gv_material gvmaterial0_

Left OUTER joins t_user_users tuserusers1_ on gvmaterial0_.create_user = tuserusers1_.id

3. Many-to-one can also be mapped by an association table, by@JoinTableannotations can be

· Defines the association table. The associated table contains foreign keys (through @jointable.joincolumns) that refer back to the entity, and foreign keys to the target entity table (through @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 to table column (Recomn??).

Jonjye nen single Test L ...

Insertable = false: The foreign key column does not appear inside the INSERT statement
updatable = false: The foreign key column does not appear in the UPDATE statement
The most common case of this usage is that there is another attribute in this class that is directly associated with a foreign key:
@Column (name= "user_id")
Long user_id;
@OneToMany
@JoinColumn (name = "User_ID", insertable = False,updatable = False)
User user;

5. Reference

Hibernate Annotations -java-iteye technology website . htm

three ways to configure many-to-one one-way using Hibernate annotations _saminar2012_ Sina blog . htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.