Write a hibernate example step three: Create an object-relational map file
The following are the specific implementation steps:
- Find the Student class sudents we want to persist
- Build Object-Relational map document Students.hbm.xml:
<?xml version= "1.0"? ><! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "http://hibernate.sourceforge.net/ Hibernate-mapping-3.0.dtd "><!--Generated 2018-7-22 16:38:57 by Hibernate Tools 3.4.0.CR1-->< hibernate-mapping> <class name= "Students" table= "Students" > <id name= "Sid" type= "int" > <column name= "SID"/> <generator class= "Assigned"/> </id> <property name= " Sname "type=" java.lang.String "> <column name=" sname "/> </property> <property N Ame= "Gender" type= "java.lang.String" > <column name= "Gender"/> </property> <pro Perty name= "Birthday" type= "java.util.Date" > <column name= "Birthday"/> </property> <property name= "Address" type= "java.lang.String" > <column name= "Address"/> </property& Gt </class&gT;Mapping our entity class to a table in the database (STUDENTS), one level maps each of our properties to a field in a database table, and column name represents the corresponding field name.
- Add the generated mapping file to the Hibernate.cfg.xml configuration document
<mapping resource= "Students.hbm.xml"/> <!--properties Resource It's written on the object we're loading--the relational mapping file---
Create a new Hibernate database
A single-table mapping of Hibernate--create object-relational mapping file