views:

139

answers:

1

Hi,

I'm trying to configure a seqhilo generator for a Hibernate application on Oracle.

<id name="idTest" type="int">
       <column name="ID_TEST" precision="6" scale="0" />
       <generator class="seqhilo">
        <param name="sequence">S_TEST</param>
        <param name="max_lo">1000</param>
       </generator>
 </id>

I created a sequence(S_TEST) in oracle database 10g, Unfortunately its not working: the id is always null. could you explain to me how to use seqhilo generator within oracle database, may be i'm confused :(

here is the generated sql trace:

08:52:44,441 DEBUG AnnotationTransactionAttributeSource:107 - Adding transactional method [create] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
08:52:44,441 DEBUG HibernateTransactionManager:346 - Using transaction object [org.springframework.orm.hibernate3.HibernateTransactionManager$HibernateTransactionObject@1786a3c]
08:52:44,441 DEBUG HibernateTransactionManager:374 - Creating new transaction with name [com.cylande.utilities.GenericDAO.create]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
08:52:44,472 DEBUG HibernateTransactionManager:496 - Opened new Session [org.hibernate.impl.SessionImpl@1bf68a9] for Hibernate transaction
08:52:44,472 DEBUG HibernateTransactionManager:507 - Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@1bf68a9]
08:52:44,487 DEBUG DriverManagerDataSource:163 - Creating new JDBC DriverManager Connection to [jdbc:oracle:thin:@localhost:1521:orcl]
08:52:44,519 DEBUG HibernateTransactionManager:572 - Exposing Hibernate transaction as JDBC transaction [oracle.jdbc.driver.T4CConnection@8c7be5]
08:52:44,519 DEBUG TransactionSynchronizationManager:186 - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@11a0d35] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@13b5a3a] to thread [main]
08:52:44,519 DEBUG TransactionSynchronizationManager:186 - Bound value [org.springframework.orm.hibernate3.SessionHolder@12c4c57] for key [org.hibernate.impl.SessionFactoryImpl@1594a88] to thread [main]
08:52:44,519 DEBUG TransactionSynchronizationManager:261 - Initializing transaction synchronization
08:52:44,534 DEBUG TransactionInterceptor:290 - Getting transaction for [com.cylande.utilities.GenericDAO.create]
08:52:44,534 DEBUG TransactionSynchronizationManager:142 - Retrieved value [org.springframework.orm.hibernate3.SessionHolder@12c4c57] for key [org.hibernate.impl.SessionFactoryImpl@1594a88] bound to thread [main]
08:52:44,550 DEBUG SQL:102 - select categorie_.ID_CATEGORIE, categorie_.CATEGORIE as CATEGORIE9_ from AHMED.CATEGORIE categorie_ where categorie_.ID_CATEGORIE=?
08:52:44,550 TRACE IntegerType:128 - binding '1' to parameter: 1
08:52:44,550 TRACE StringType:170 - returning 'Test dintegration' as column: CATEGORIE9_
08:52:44,550 DEBUG TransactionInterceptor:319 - Completing transaction for [com.cylande.utilities.GenericDAO.create]
08:52:44,550 DEBUG HibernateTransactionManager:880 - Triggering beforeCommit synchronization
08:52:44,550 DEBUG HibernateTransactionManager:893 - Triggering beforeCompletion synchronization
08:52:44,550 DEBUG HibernateTransactionManager:707 - Initiating transaction commit
08:52:44,566 DEBUG HibernateTransactionManager:651 - Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@1bf68a9]
08:52:44,566 DEBUG SQL:102 - insert into AHMED.TEST (ID_APPLICATION, ID_MODULE, ID_CATEGORIE, ID_PAGE, NOM_TEST, DESCRIPTION_TEST, ID_TEST) values (?, ?, ?, ?, ?, ?, ?)
08:52:44,566 TRACE IntegerType:121 - binding null to parameter: 1
08:52:44,566 TRACE IntegerType:121 - binding null to parameter: 2
08:52:44,566 TRACE IntegerType:128 - binding '1' to parameter: 3
08:52:44,566 TRACE IntegerType:121 - binding null to parameter: 4
08:52:44,566 TRACE StringType:128 - binding 'nomTest2' to parameter: 5
08:52:44,566 TRACE IntegerType:128 - binding '0' to parameter: 7
08:52:44,581  WARN JDBCExceptionReporter:77 - SQL Error: 1, SQLState: 23000
08:52:44,581 ERROR JDBCExceptionReporter:78 - ORA-00001: violation de contrainte unique

the field that must be generated (id_Test) is always equal to zero even if i changed the generator to sequence or native the result remain the same

+1  A: 

The declaration looks correct, or at least very close to the sample from the documentation:

5.1.4.2. Hi/lo algorithm

The hilo and seqhilo generators provide two alternate implementations of the hi/lo algorithm. The first implementation requires a "special" database table to hold the next available "hi" value. Where supported, the second uses an Oracle-style sequence.

<id name="id" type="long" column="cat_id">
        <generator class="seqhilo">
                <param name="sequence">hi_value</param>
                <param name="max_lo">100</param>
        </generator>
</id>

But in order to debug the issue, I would try to

  • activate the logging of the generated SQL to see what is happening exactly (and post the result)
  • stick to the above example i.e. define the column in the id element and use a long
    • if this works, start modifying the configuration
Pascal Thivent
I did exactly as you say (i changed the field type ..) but the id is always equal to zero even with other generator(sequence,native)
@user405458 Can you confirm that the following `select S_TEST.nextval from dual` returns something?
Pascal Thivent
Yes, I run this query and the result is incremented at each call
@user405458 Weird. I'll see if I can reproduce. But this is supposed to work...
Pascal Thivent