简体   繁体   中英

Why don't Grails automatic timestamp fields work consistently in Oracle?

I'm making use of Grails built-in dateCreated and lastUpdated fields. Here's an example of the domain:

class ExampleObject {
    String name;
    Date dateCreated
    Date lastUpdated
}

When saving this object using the in-memory H2 database, it works fine. However, when I run the same code against Oracle 11g, it fails with the following error.

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)

I've noticed that this issue seems to arise when creating the object and then immediately modifying it. For reference, I'm using Grails 2.3.1 and Oracle 11.2.0.2.0. How can I fix this?

Add the following to your Config.groovy :

grails.gorm.default.mapping = {
    id(generator: "sequence-identity")
}

For more information, take a look at the discussion on the related Grails defect .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM