Hibernate needs to know how to load (load) and store persisted classes of objects. This is what Hibernate
Where the file plays a role. The mapping file tells Hibernate which table it should access in the database
(table) and which fields within the table should be used (column).
The basic structure of a mapping file looks like this:
If you need to look at the DTD configuration file can go to the Hibernate3.jar file under the Org.hibernate package there is a HIBERNATE-MAPPING-3.0.DTD and Hibernate-configuration-3.0.dtd file is the constraint here
A class element is included between the hibernate-mapping tag. All persisted entity classes (again the sound
, perhaps the next dependent class, or those secondary entities, requires a mapping to map class objects to
Tables in the SQL database:
<?xml version= "1.0"? ><! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "http://www.hibernate.org/dtd/ Hibernate-mapping-3.0.dtd ">
<!--Here the event is the class name, and the package path above is the packet of this class name, events is the corresponding table name--
<class name= "Event" table= "EVENTS" >
<!--the Name property of the ID tag here is a property of the corresponding class, and column is the primary key name of the corresponding table--
<id name= "id" column= "event_id" >
<!--generator element specifies the generation strategy of the identifier (that is, how the identifier value is generated) native (globally unique) increment (self-increment)--
<generator class= "Native" > </generator>
</id>
<!--There is a lot of writing here, the first is to write the table and type together, the other is not written when hibernate will automatically use the default configuration--
<property name= "date" type= "timestamp" column= "Event_date"/>
<property name= "title"/>
<!--This is the name of the data type, separate the table fields into a single label, because the table also has some of its own properties--
<property name= "name" type= "Java.lang.String" >
<column name= "Name" not-null= "true"/>
</property>
</class>
In order to save Hibernate configuration, we can use a simple hibernate.properties file, or a
A slightly more complex hibernate.cfg.xml can even be used to configure hibernate entirely using the program. Most users prefer to use
XML configuration file:
<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "http// Hibernate.sourceforge.net/hibernate-configuration-3.0.dtd ">
mapping files for Java-hibernate