View RSS Feed

My Java Tips

Hibernate - Mapping files

Rate this Entry
by , 10-30-2011 at 05:45 PM (1106 Views)
Mapping files are there to map entities with the database tables. In this post, I will present 2 sample mapping files.


Mapping file for MySql is given below:
<pre lang="java">
<!--?xml version="1.0" encoding="UTF-8"?-->

<hibernate-mapping>
<class name="com.domain.example.Student" table="student">
<id name="id" column="id" type="java.lang.Integer">
<generator class="increment">
</generator></id>
<property name="name" column="name" type="java.lang.String"></property>
<property name="subject" column="taste" type="java.lang.String"></property>
</class>
</hibernate-mapping></pre>
Mapping file for Posgres is given below:
<pre lang="java">
<!--?xml version="1.0" encoding="UTF-8"?-->

<hibernate-mapping>
<class name="com.domain.example.Student" table="student">
<id name="id" column="id" type="java.lang.Integer">
<generator class="sequence">
<param name="sequence"></param>student_id_seq

</generator>

</id>
<property name="name" column="name" type="java.lang.String"></property>
<property name="subject" column="taste" type="java.lang.String"></property>
</class>
</hibernate-mapping></pre>

Submit "Hibernate - Mapping files" to Facebook Submit "Hibernate - Mapping files" to Digg Submit "Hibernate - Mapping files" to del.icio.us Submit "Hibernate - Mapping files" to StumbleUpon Submit "Hibernate - Mapping files" to Google

Tags: None Add / Edit Tags
Categories
Hibernate

Comments