Greg Pagendam-Turner
Greg Pagendam-Turner

Reputation: 2492

Map Joda DateTime to Oracle Timestamp in Grails

I'm trying to map the lastUpdated, dateCreated fields in a Grails domain object to a field of type TIMESTAMP in an existing Oracle database

import org.grails.datastore.gorm.events.AutotimestampEventListener
import org.joda.time.*
import org.joda.time.contrib.hibernate.*

class Branch {
    String idErpBranch
    String createdBy
    DateTime dateCreated
    String updatedBy
    DateTime lastUpdated

    static constraints = {

    }

    static mapping = {
        autoTimestamp true
        table 'branch'
        version false
        id column: 'id_branch'
        idErpBranch column: 'id_erp_branch'
        createdBy column: 'id_created_by'
        dateCreated column: 'ts_created'
        updatedBy column: 'id_updated_by'
        lastUpdated column: 'ts_updated'
    }
}

When I run grails runApp I get the following error:

Caused by HibernateException: Wrong column type in PRODSOA.BRANCH for column ts_created. Found: timestamp, expected: raw(255)

How do we map these Joda fields onto an Oracle TIMESTAMP field?

Upvotes: 0

Views: 1218

Answers (1)

user800014
user800014

Reputation:

If you're using the Grails Joda plugin you need to map the user type for each Joda type.

In the documentation you can see that this can be done using the command install-joda-time-gorm-mappings:

The Joda Time plugin can even do this for you so long as you do not already have a grails.gorm.default.mapping section in your Config.groovy file. Just run grails install-joda-time-gorm-mappings and the plugin will add the standard mappings for all supported user types to your Config.groovy file.

And if you don't need to handle the TimeZone, you can change your mapping to LocalDateTime.

Upvotes: 1

Related Questions