Write in front:
There are two ways to configure the mapping of entity classes to databases:
1. Using *.hbm.xml
2. Use @ annotations
Two: How to configure XML:
Eg: an employee's XML configuration file:
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE hibernate-mapping Public '-//hibernate/hibernate mapping DTD 3.0//en ' http://www.hibernate.org/ Dtd/hibernate-mapping-3.0.dtd '><hibernate-mapping> <classname= "Edu.hue.erp.auth.emp.vo.EmpModel"Table= "Tbl_emp"> <!--ID PRIMARY Key configuration: Id-name: Attribute name in entity class Column-name: Primary key name in database table Generator-class: Primary key generation Policy - <IDname= "UUID" > <!--When the primary key field name in a database table is the same as the attribute name of the entity class, column can omit the write - <!--<column name= "uuid" ></column> - <Generatorclass= "Native"></Generator> </ID> <!--Property : Configuration of non-primary key properties Property-name: attribute name in entity class Column-name: Field name in database table for attribute in entity class - <!--When the primary key field name in a database table is the same as the attribute name of the entity class, column can omit the write - <!--<property name= "username" > <column name= "username"/> </property> - < Propertyname= "username"/> < Propertyname= "pwd"/> < Propertyname= "Name"/> < Propertyname= "Tele"/> < Propertyname= "Address"/> < Propertyname= "Email"/> < Propertyname= "Gender"/> < Propertyname= "Birthday"/> < Propertyname= "Lastlogintime"/> < Propertyname= "Lastloginip"/> < Propertyname= "Logintimes"/> <!--employee-to-department relationship - <!--Name: Same as the Department object name contained in the Employee Entity Class column: Foreign key in employee table (primary key of Department) class: The full path of a class in a party - <Many-to-onename= "DM"column= "Depuuid"class= "Edu.hue.erp.auth.dep.vo.DepModel" /> <!--Many-to-many roles for employees - <!--Name: Consistent with the name of the role object contained in the Employee Entity Class table: Intermediate table name Key-column: Primary key for employee table Many-to-many--column: Role primary key Many-to-many--class: Full path of the role class - <Setname= "Roles"Table= "Tbl_emp_role"> <Keycolumn= "Empuuid"/> <Many-to-manycolumn= "Roleuuid"class= "Edu.hue.erp.auth.role.vo.RoleModel"/> </Set> </class></hibernate-mapping><!--In addition, in the department's configuration file://Department to the employee one-to-many//private set<employee> emps; When cascading deletes, a party object first discards the relationship with the multiple parties, converting to set the foreign key field to null if the foreign key field is set to not allow NULL, the following exception is thrown Java.sql.BatchUpdateE Xception:column ' depuuid ' cannot be null at this time only need to make the relationship maintenance, so that one side object does not maintain the relationship, do not manipulate the foreign key —————— Inverse=true <set name= "Emps" cascade= "delete" inverse= "true" > <key column= "Depuuid"/> < One-to-many class= "Edu.hue.erp.auth.emp.vo.EmpModel"/> </set>//attention to the employee-to-employees-to-department column is a Caused by -
Oh, my God, it's sangjintianliang. Less than 150 words are not allowed to be published and are not allowed to be published.
Really, do not insert the code is not counted words .... Good.. Very good... Then we'll come together and make up and make up, gather and gather
Enough of these 150 words ...
hibernate--using XML to configure mapping relationships