Hibernate video learning notes (10) Other Mappings

Source: Internet
Author: User

ComponentIng

 

InHibernateMedium, ComponentIs the logical component of an object,The fundamental difference between it and entity is that there is noOid,

ComponentCan be a value object (Ddd)

 

UseComponentBenefits of ing: it achieves fine-grained division of object models, with more distinct layers and higher reuse rates.

<Class name = "com. bjsxt. hibernate. User" table = "t_user">

<ID name = "ID">

<Generator class = "native"/>

</ID>

<Property name = "name"/>

<Component name = "Contact">

<Property name = "email"/>

<Property name = "Address"/>

<Property name = "zipcode"/>

<Property name = "contacttel"/>

</Component>

</Class>

 

The corresponding table is stillUserTable is only an object strength subdivision

 

User user = new user ();

User. setname ("Zhang San");

Contact contact = new contact ();

Contact. setaddress ("XXXXX ");

Contact. setemail ("xxx@rrr.com ");

Contact. setzipcode ("1111111 ");

Contact. setcontacttel ("9999999999 ");

User. setcontact (contact );

Session. Save (User );

 

Composite primary key ing

Composite (union) primary key ing

 

Generally, attributes related to the composite primary key are put into a class separately.

*This class must implement the serialization Interface

*OverwriteHashcodeAndEqualsMethod

 

Public class fiscalyearperiodpk implements serializable {

 

//Accounting Year

Private int fiscalyear;

//Monthly accounting

Private int fiscalperiod;

 

Public int getfiscalyear (){

Return fiscalyear;

}

 

Public void setfiscalyear (INT fiscalyear ){

This. fiscalyear = fiscalyear;

}

 

Public int getfiscalperiod (){

Return fiscalperiod;

}

 

Public void setfiscalperiod (INT fiscalperiod ){

This. fiscalperiod = fiscalperiod;

}

 

@ Override

Public int hashcode (){

Final int prime = 31;

Int result = 1;

Result = prime * result + fiscalperiod;

Result = prime * result + fiscalyear;

Return result;

}

 

@ Override

Public Boolean equals (Object OBJ ){

If (this = OBJ)

Return true;

If (OBJ = NULL)

Return false;

If (getclass ()! = Obj. getclass ())

Return false;

Final fiscalyearperiodpk Other = (fiscalyearperiodpk) OBJ;

If (fiscalperiod! = Other. fiscalperiod)

Return false;

If (fiscalyear! = Other. fiscalyear)

Return false;

Return true;

}

}

 

<Class name = "com. bjsxt. hibernate. fiscalyearperiod" table = "t_fiscal_year_period">

<Composite-ID name = "fiscalyearperiodpk">

<Key-property name = "fiscalyear"/>

<Key-property name = "fiscalperiod"/>

</Composite-ID>

<Property name = "begindate"/>

<Property name = "enddate"/>

<Property name = "periodsts"/>

</Class>

 

In the inheritance ing, ifClassOfAbstractAttributeTrueNo table is generated.

 

Set

List

Array

Map

T_collectionmapping

id

name

1

Xxx

 

T_set_values

set_id

set_value

1

A

1

B

 

T_list_value

list_id

list_value

list_index

1

C

0

1

D

1

 

T_array_value

array_id

array_value

array_index

1

E

0

1

F

1

 

T_map_value

map_id

map_key

map_value

1

k1

V1

1

K2

V2

 

<ID name = "ID">

<Generator class = "native"/>

</ID>

<Property name = "name"/>

<Set name = "setvalue" table = "t_set_value">

<Key column = "set_id"/>

<Element type = "string" column = "set_value"/>

</Set>

<List name = "listvalue" table = "t_list_value">

<Key column = "list_id"/>

<List-index column = "list_index"/> //To save order

<Element type = "string" column = "list_value"/>

</List>

<Array name = "arrayvalue" table = "t_array_value">

<Key column = "array_id"/>

<List-index column = "array_index"/>

<Element type = "string" column = "array_value"/>

</Array>

<Map Name = "mapvalue" table = "t_map_value">

<Key column = "map_id"/>

<Map-Key type = "string" column = "map_key"/>

<Element type = "string" column = "map_value"/>

</Map>

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.