Hibernate mapping 1

Source: Internet
Author: User
Tags field table

Hibernet Mapping

Collection mappings:

The property fields of the class are collections.

Set

<set name= "property field" table= "property Field table Name" >

<key foreign key column= "" >

<element column= "Property stores the location name of the content" Type= "" >

Mapping of Set collection properties

Name specifies the properties of the set collection to be mapped

Table to which to map table collection properties

KEY specifies the foreign key field of the collection table (t_address)

element specifies other fields of the collection table

Type element, be sure to specify

List

<list name= "property field" table= "property Field table Name" >

<key foreign key column= "" >

<list-index column= "Index" > list is ordered, this is used to sort the

<element column= "Property stores the location name of the content" Type= "" >

--

List Collection Mappings

LIST-INDEX Specifies the name of the row sequence (because the list collection is guaranteed to be ordered)

Map

<map name= "property field" table= "property Field table Name" >

<key foreign key column= "" >

<map-key column= "First content: Property stores the location name of the content" Type= "" >

<element column= "Second content: property stores the location name of the content" Type= "" >

Map for map Collection

KEY specifies the foreign key field

Map-key the key of the specified map

element specifies the value of map

One-to-many, many-to-a

<many-to-one name= "property field" calss= "The name of another class" column= "Foreign key Field" >

<one-to-mony calss= "Name of another class" >

In a one-to-many-to-many relationship, the best way to preserve the data is to maintain the relationship through many parties, which can reduce the generation of the UPDATE statement and improve hibernate execution efficiency!

Attention:

Configure which party, which has to maintain the rights of the association relationship!

Inverse property

The inverse property is useful when maintaining an association relationship.

Indicates whether control is transferred. (works on one side)

Inverse, control reversal.

Inverse = false does not reverse; when there is control over the front

True control reversal; current party has no control

Cascade indicates that a cascade operation "can be set to one or more of the other side"

None cascade operation, default value

Save-update Cascade Save or update

Delete Cascade deletion

Save-update,delete Cascade Save, UPDATE, delete

All ibid. Cascade Save, UPDATE, delete

Many-to-many

<many-to-many column=" the ID of another class " class=" the name of another class " ></ Many-to-many>

Many-to-many

column specifies the item field corresponding to the Foreign key field

Type of class collection element

Hibernate mapping 1

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.