简体   繁体   English

GORM IdentityEnumType 映射 NPE 与 Grails 2.5.6

[英]GORM IdentityEnumType mapping NPE with Grails 2.5.6

I have an application that I am trying to upgrade from Grails 2.0.3 to Grails 2.5.6.我有一个应用程序正在尝试从 Grails 2.0.3 升级到 Grails 2.5.6。 Many of the domain classes map enums using IdentityEnumType:许多使用 IdentityEnumType 的域类 map 枚举:

import org.codehaus.groovy.grails.orm.hibernate.cfg.IdentityEnumType
...
class Account {
    Long id
    ...
    AccountType accountType
    ...
    static mapping = {
        id generator: 'sequence', params: [sequence: 'account_id_seq']
        accountType(type: IdentityEnumType, length: 1)
        ...
    }

    enum AccountType {
        INTERNAL("I", "Internal"),
        ...
        String id
        String name

        AccountType(String id, String name) { .. }
    }
}

The app throws a NPE on startup:该应用程序在启动时抛出 NPE:

Caused by: org.hibernate.MappingException: Unable to instantiate custom type: org.codehaus.groovy.grails.orm.hibernate.cfg.IdentityEnumType
    at org.hibernate.type.TypeFactory.custom(TypeFactory.java:187) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.type.TypeFactory.custom(TypeFactory.java:174) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.type.TypeFactory.byClass(TypeFactory.java:99) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.type.TypeResolver.heuristicType(TypeResolver.java:170) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:297) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:290) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.mapping.Property.isValid(Property.java:243) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:464) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.mapping.RootClass.validate(RootClass.java:235) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.cfg.Configuration.validate(Configuration.java:1362) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1865) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration.buildSessionFactory(GrailsAnnotationConfiguration.java:135) ~[grails-datastore-gorm-hibernate-3.1.4.RELEASE.jar:na]
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:793) ~[spring-orm-4.1.9.RELEASE.jar:4.1.9.RELEASE]
    at org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.newSessionFactory(ConfigurableLocalSessionFactoryBean.java:245) ~[grails-datastore-gorm-hibernate-3.1.4.RELEASE.jar:na]
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:715) ~[spring-orm-4.1.9.RELEASE.jar:4.1.9.RELEASE]
    at org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.buildSessionFactory(ConfigurableLocalSessionFactoryBean.java:191) ~[grails-datastore-gorm-hibernate-3.1.4.RELEASE.jar:na]
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:189) ~[spring-orm-4.1.9.RELEASE.jar:4.1.9.RELEASE]
    at org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.afterPropertiesSet(ConfigurableLocalSessionFactoryBean.java:235) ~[grails-datastore-gorm-hibernate-3.1.4.RELEASE.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631) ~[spring-beans-4.1.9.RELEASE.jar:4.1.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568) ~[spring-beans-4.1.9.RELEASE.jar:4.1.9.RELEASE]
    ... 45 common frames omitted
Caused by: org.hibernate.MappingException: Error mapping Enum Class using IdentifierEnumType
    at org.codehaus.groovy.grails.orm.hibernate.cfg.IdentityEnumType.setParameterValues(IdentityEnumType.java:116) ~[grails-datastore-gorm-hibernate-3.1.4.RELEASE.jar:na]
    at org.hibernate.type.TypeFactory.injectParameters(TypeFactory.java:127) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    at org.hibernate.type.TypeFactory.custom(TypeFactory.java:183) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
    ... 64 common frames omitted
Caused by: java.lang.NullPointerException: null
    at org.codehaus.groovy.grails.orm.hibernate.cfg.IdentityEnumType.setParameterValues(IdentityEnumType.java:103) ~[grails-datastore-gorm-hibernate-3.1.4.RELEASE.jar:na]
    ... 66 common frames omitted

The code us looking for an enumClass key in a null properties instance.我们在 null 属性实例中寻找 enumClass 键的代码。 Anyone know how to get this to work?任何人都知道如何让它工作?

I am using:我在用:

plugins {... compile ":hibernate:3.6.10.19"插件{...编译“:hibernate:3.6.10.19”

Thanks David谢谢大卫

You have to specify the enum class name in a params map:您必须在参数 map 中指定枚举 class 名称:

static mapping = {
    accountType(type: IdentityEnumType, length: 1, params: [enumClass: AccountType.name])
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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