1 Reply Latest reply on Nov 19, 2012 4:31 PM by 576227

    Oracle dialect does not support identity key generation


      I'm trying to run an integration tests suite against an Oracle 10g XE database server on a Linux box. But I have one issue that makes all the tests in error. Here is the message I get for each and every test:

      ]Results :

      Tests in error:
      testSaveAndRetrieve(com.thalasoft.learnintouch.cor e.dao.AdminDaoTest): com.thalasoft.learnintouch.core.dao.dialect.Custom Oracle10gDialect does not support identity key generation; nested exception is org.hibernate.MappingException: com.thalasoft.learnintouch.core.dao.dialect.Custom Oracle10gDialect does not support identity key generation

      I wonder what kind of domain classes mapping setup is required for Hibernate to correctly talk to Oracle.

      Also, I hope I can keep the domain classes mapping setup common to MySql and Oracle and not be forced to have one specific for each database server.

      I'm using the Oracle driver ojdbc14 with Spring 3.1.3.RELEASE and Hibernate 3.6.9.Final versions.

      Here is my Hibernate Spring setup and a domain class mapping setup:

      <bean id="sessionFactory"
                <property name="dataSource">
                     <ref bean="dataSource" />
                <property name="mappingDirectoryLocations">
                <property name="mappingResources">
                <property name="hibernateProperties">
                          <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                          <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                          <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
                          <prop key="hibernate.show_sql">true</prop>
                          <prop key="hibernate.format_sql">true</prop>
                          <prop key="hibernate.c3p0.min_size">5</prop>
                          <prop key="hibernate.c3p0.max_size">20</prop>
                          <prop key="hibernate.c3p0.timeout">1800</prop>
                          <prop key="hibernate.c3p0.max_statements">50</prop>

           <!-- Setup the Spring transaction manager -->
           <bean id="transactionManager"
                <property name="sessionFactory">
                     <ref local="sessionFactory" />

           <tx:annotation-driven />

           <bean          class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />

           <!-- Translate dao exceptions into Spring exceptions -->
           <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

      The Hibernate mapping:

      <?xml version="1.0"?>
      <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
           <class name="com.thalasoft.learnintouch.core.domain.Admin" table="admin"
                dynamic-insert="true" dynamic-update="true">
                <id name="id" type="java.lang.Integer">
                     <column name="id" />
                     <generator class="identity" />
                <version name="version" type="int">
                     <column name="version" not-null="true" />
                <property name="login" type="string">
                     <column name="login" length="50" not-null="true" unique="true" />
                <property name="password" type="string">
                     <column name="password" length="100" not-null="true" />
                <property name="passwordSalt" type="string">
                     <column name="password_salt" length="50" />
                <property name="firstname" type="string">
                     <column name="firstname" not-null="true" />
                <property name="lastname" type="string">
                     <column name="lastname" not-null="true" />
                <property name="email" type="string">
                     <column name="email" not-null="true" />
                <property name="superAdmin" type="boolean">
                     <column name="super_admin" not-null="true" />
                <property name="preferenceAdmin" type="boolean">
                     <column name="preference_admin" not-null="true" />
                <property name="address" type="string">
                     <column name="address" />
                <property name="zipCode" type="string">
                     <column name="zip_code" length="10" />
                <property name="city" type="string">
                     <column name="city" />
                <property name="country" type="string">
                     <column name="country" />
                <property name="profile" type="text">
                     <column name="profile" length="65535" />

      I'm also using a custom dialect:

      public class CustomOracle10gDialect extends Oracle10gDialect {

           public CustomOracle10gDialect() {
                registerColumnType(Types.LONGVARCHAR, "clob");
           registerColumnType(Types.LONGNVARCHAR, "clob");
           registerColumnType(Types.INTEGER, "number");
           registerColumnType(Types.BIT, "number");
           registerColumnType(Types.TIMESTAMP, "date");


      The schema definition:

      create table admin (
      id number(10) not null,
      version number(10) not null,
      firstname varchar2(255) not null,
      lastname varchar2(255) not null,
      login varchar2(50) not null,
      constraint admin_login_u1 unique (login),
      password varchar2(100) not null,
      password_salt varchar2(50),
      super_admin number(1) not null check (super_admin in (0, 1)),
      preference_admin number(1) not null check (preference_admin in (0, 1)),
      address varchar2(255),
      zip_code varchar2(10),
      city varchar2(255),
      country varchar2(255),
      email varchar2(255),
      profile clob,
      constraint admin_pk primary key (id)
      create sequence sq_id_admin increment by 1 start with 1 nomaxvalue nocycle cache 10;
      create or replace trigger tr_id_inc_admin
      before insert
      on admin
      for each row
      select sq_id_admin.nextval into :new.id from dual;
        • 1. Re: Oracle dialect does not support identity key generation
          Here is how I solved the issue:

                    <id name="id" type="java.lang.Integer">
                         <column name="id" />
                         <generator class="native"><param name="sequence">sq_id_admin</param></generator>

          I can thus have only one domain class mapping file working on both MySql and Oracle database servers, this with one sequence per table in the case of Oracle.