dotCMS - Open Source Content Management System, Ondemand CMS, and Professional Support

Document Search

Article Information

Since Version: 1.7
Tags: plugins
Updated: 4/23/2009 4:30:18 PM
By: Jason Tesser
Doc id: 170477
Print Page: Export to PDF

Using Hibernate

dotCMS doesn't use much of the Hibernate stack. dotCMS primarily uses Hibernate as a DB abstraction layer to ease SQL to the different DBs it supports. If you need to add Hibernate Mappings you can do it right within your plugin. There are 2 mapping files you need to configure it for. Many times they are the same mapping though. There is one file DotCMSId.hbm.xml for MySQL and MSSQL because they have auto generated primary keys and a second file DotCMSSeq.hbm.xml for Postgres and Oracle because they use Sequences. Keep in mind that if you want to do straight SQL you can and dotCMS provides great utilities like DotConnect to ease your SQL logic. Below is an example of a hibernate mapping

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
	<class name="com.dotmarketing.plugins.hello.world.HelloBean" table="hello_world_bean">
		<id name="id" column="id" type="string" unsaved-value="any">
			<!-- generator class="native"/ -->
			<generator class="sequence">
				<param name="sequence">hello_world_bean_id_seq</param>
			</generator>
		</id>
		<property name="Name" column="name" type="string" not-null="true"/>			
	</class>	
</hibernate-mapping>

And for Oracle and Postgres

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
	<class name="com.dotmarketing.plugins.hello.world.HelloBean" table="hello_world_bean">
		<id name="id" column="id" type="string" unsaved-value="any">
			<!-- generator class="native"/ -->
			<generator class="sequence">
				<param name="sequence">hello_world_bean_id_seq</param>
			</generator>
		</id>
		<property name="Name" column="name" type="string" not-null="true"/>			
	</class>	
</hibernate-mapping>


Post a Comment


Add Comments

   

 
Post