Using Hibernate in OSGI Plugins - Documentation topics on: database,hibernate,sql,using hibernate,.

Using Hibernate in OSGI Plugins

dotCMS uses Hibernate, primarily as a DB abstraction layer to ease SQL to the different DBs it supports. Since dotCMS uses the Hibernate stack, if you wish to use Hibernate in your own plugin, you must map the dotCMS Hibernate classes.

The databases dotCMS supports use two different access methods, so you must configure 2 different mapping files:

  • DotCMSId.hbm.xml is used for MySQL and MSSQL, because they have auto generated primary keys.
  • DotCMSSeq.hbm.xml is used for Postgres and Oracle, because they use Sequences.

Note: Hibernate is not required for database access; you may instead access the database using SQL directly, and dotCMS provides useful utilities like DotConnect to simplify your SQL logic.

Example Mapping for MySQL and MSSQL (DotCMSId.hbm.xml)

<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>
                hello_world_bean_id_seq
            </generator>
        </id>
        <property name="Name" column="name" type="string" not-null="true">
        </property>
    </class>
</hibernate-mapping>')</pre>

Example Mapping for Oracle and Postgres (DotCMSSeq.hbm.xml)

<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>
                hello_world_bean_id_seq
            </generator>
        </id>
        <property name="Name" column="name" type="string" not-null="true">
        </property>
    </class>
</hibernate-mapping>