A single-table mapping of Hibernate--create object-relational mapping file

Source: Internet
Author: User

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 database

Create a new Hibernate database

A single-table mapping of Hibernate--create object-relational mapping file

Related Article

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.