Hibernate/Oracle seqhilo 生成器
我正在尝试为 Oracle 上的 Hibernate 应用程序配置 seqhilo 生成器。
<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>
我在oracle数据库10g中创建了一个序列(S_TEST),不幸的是它不起作用:id始终为空。 你能向我解释一下如何在oracle数据库中使用seqhilo生成器吗,可能我很困惑:(
这是生成的sql跟踪:
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
必须生成的字段(id_Test)始终等于0,即使我将生成器更改为序列或本机结果保持不变
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该声明看起来正确,或者至少非常接近文档中的示例:
但为了调试问题,我会尝试
id
元素中定义列并使用long
The declaration looks correct, or at least very close to the sample from the documentation:
But in order to debug the issue, I would try to
id
element and use along