This discussion is archived
1 Reply Latest reply: Nov 19, 2012 8:31 AM by 576227 RSS

Oracle dialect does not support identity key generation

576227 Newbie
Currently Being Moderated
Hello,

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 10.2.0.4.0 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"
          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
          <property name="dataSource">
               <ref bean="dataSource" />
          </property>
          <property name="mappingDirectoryLocations">
               <list>
                    <value>classpath:com/thalasoft/learnintouch/core/domain</value>
               </list>
          </property>
          <property name="mappingResources">
               <list>
                    <value>com/thalasoft/learnintouch/core/domain/typedef.hbm.xml</value>
               </list>
          </property>
          <property name="hibernateProperties">
               <props>
                    <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>
               </props>
          </property>
     </bean>

     <!-- Setup the Spring transaction manager -->
     <bean id="transactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager">
          <property name="sessionFactory">
               <ref local="sessionFactory" />
          </property>
     </bean>

     <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"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
     <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" />
          </id>
          <version name="version" type="int">
               <column name="version" not-null="true" />
          </version>
          <property name="login" type="string">
               <column name="login" length="50" not-null="true" unique="true" />
          </property>
          <property name="password" type="string">
               <column name="password" length="100" not-null="true" />
          </property>
          <property name="passwordSalt" type="string">
               <column name="password_salt" length="50" />
          </property>
          <property name="firstname" type="string">
               <column name="firstname" not-null="true" />
          </property>
          <property name="lastname" type="string">
               <column name="lastname" not-null="true" />
          </property>
          <property name="email" type="string">
               <column name="email" not-null="true" />
          </property>
          <property name="superAdmin" type="boolean">
               <column name="super_admin" not-null="true" />
          </property>
          <property name="preferenceAdmin" type="boolean">
               <column name="preference_admin" not-null="true" />
          </property>
          <property name="address" type="string">
               <column name="address" />
          </property>
          <property name="zipCode" type="string">
               <column name="zip_code" length="10" />
          </property>
          <property name="city" type="string">
               <column name="city" />
          </property>
          <property name="country" type="string">
               <column name="country" />
          </property>
          <property name="profile" type="text">
               <column name="profile" length="65535" />
          </property>
     </class>
</hibernate-mapping>

I'm also using a custom dialect:

public class CustomOracle10gDialect extends Oracle10gDialect {

     public CustomOracle10gDialect() {
          super();
          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
declare
begin
select sq_id_admin.nextval into :new.id from dual;
end;
/
  • 1. Re: Oracle dialect does not support identity key generation
    576227 Newbie
    Currently Being Moderated
    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>
              </id>

    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.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points