我正在使用Grails内置的dateCreated和lastUpdated字段。以下是域名的示例:
class ExampleObject {
String name;
Date dateCreated
Date lastUpdated
}
使用内存H2数据库保存此对象时,它可以正常工作。但是,当我针对Oracle 11g运行相同的代码时,它会因以下错误而失败。
org.codehaus.groovy.grails.orm.hibernate.events.PatchedDefaultFlushEventListener:213 Could not synchronize database state with session
org.hibernate.QueryTimeoutException: could not update: [com.example.ExampleObject#948]
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.sql.SQLException: ORA-01407: cannot update ("SOME_USER"."EXAMPLE_OBJECT"."DATE_CREATED") to NULL
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1044)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1329)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3665)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1352)
我注意到在创建对象然后立即修改它时似乎会出现此问题。作为参考,我使用的是Grails 2.3.1和Oracle 11.2.0.2.0。我该如何解决这个问题?
答案 0 :(得分:2)
将以下内容添加到Config.groovy
:
grails.gorm.default.mapping = {
id(generator: "sequence-identity")
}
有关详细信息,请查看the discussion on the related Grails defect。