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
T_set_values
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>