View RSS Feed

My Java Tips

Creating a Hibernate archive

Rate this Entry
by , 11-06-2011 at 05:20 PM (1213 Views)
Consider a simple POJO with no direct coupling to Hibernate. The details of the Hibernate mapping will be specified in the Player.hbm.xml file.




Player.hbm.xml is shown below.

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.jboss.roster.Player" table="PlayerBean">
<id name="id" type="string" column="playerID">
<generator class="assigned">
</generator></id>
<property name="position" type="string" column="POS"></property>
<property name="name" type="string" column="name"></property>
<property name="salary" type="float" column="salary"></property>
</class>
</hibernate-mapping>

Apart from mapping file, there needs to be a file that creates MBean which will manage hibernate configurations. We call that file hibernate-service.xml.

<server>
<mbean code="org.jboss.hibernate.jmx.Hibernate">name="jbo ss.har:service=Hibernate"&gt;
<attribute name="DatasourceName">java:/DefaultDS</attribute>
<attribute name="Dialect">org.hibernate.dialect.HSQLDialect</attribute>
<attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute>
<attribute name="CacheProviderClass">
org.hibernate.cache.HashtableCacheProvider
</attribute>
<!-- <attribute name="Hbm2ddlAuto">create-drop</attribute> -->
</mbean>
</server>

Submit "Creating a Hibernate archive" to Facebook Submit "Creating a Hibernate archive" to Digg Submit "Creating a Hibernate archive" to del.icio.us Submit "Creating a Hibernate archive" to StumbleUpon Submit "Creating a Hibernate archive" to Google

Tags: None Add / Edit Tags
Categories
Hibernate , XML

Comments