添加另一个数据源后,默认数据源上的“IllegalArgumentException:null source”(Grails 2.1.2)

时间:2014-01-21 21:46:37

标签: grails datasource gorm

当我尝试添加另一个数据源时出现问题(grails 2.1.2,mysql-connector-java 5.1.21)

  1. 在配置文件中添加了第二个数据源(dataSource_customer)

    dataSource {
        url ="jdbc:mysql://localhost/defsource"
        username = "defsource"
        password = "defsource"
    }
    
    dataSource_customer {
        url ="jdbc:mysql://localhost/customer_db"
        username = "customer"
        password = "customer"
    }
    
  2. 2定义了一个新类,将datasource设置为customer

    class SensitiveDataExample {
        String analysisName
    
        static constraints = {
            analysisName nullable: false, blank: false, maxSize: 50
        }
    
        static mapping = {
            datasource('customer')
        }
    }
    

    有了这个,我可以毫无问题地访问SensitiveDataExample。但是,当我尝试访问任何其他域对象时,我得到以下异常

    Caused by: java.lang.IllegalArgumentException: null source
       at java.util.EventObject.<init>(EventObject.java:56) ~[na:1.7.0_07]
       at org.springframework.context.ApplicationEvent.<init>(ApplicationEvent.java:42) ~[spring-context-3.1.3.RELEASE.jar:3.1.3.RELEASE]
       at org.grails.datastore.mapping.engine.event.AbstractPersistenceEvent.<init>(AbstractPersistenceEvent.java:48) ~[grails-datastore-core-1.1.1.RELEASE.jar:na]
       at org.grails.datastore.mapping.engine.event.SaveOrUpdateEvent.<init>(SaveOrUpdateEvent.java:20) ~[grails-datastore-core-1.1.1.RELEASE.jar:na]
       at org.codehaus.groovy.grails.orm.hibernate.support.ClosureEventTriggeringInterceptor.onSaveOrUpdate(ClosureEventTriggeringInterceptor.java:106) ~[grails-hibernate-2.1.2.jar:2.1.2]
       at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:685) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
       at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:677) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
       at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:673) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
       at org.codehaus.groovy.grails.orm.hibernate.metaclass.SavePersistentMethod$1.doInHibernate(SavePersistentMethod.java:58) ~[grails-hibernate-2.1.2.jar:2.1.2]
       at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]
       at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]
       at org.codehaus.groovy.grails.orm.hibernate.metaclass.SavePersistentMethod.performSave(SavePersistentMethod.java:56) ~[grails-hibernate-2.1.2.jar:2.1.2]
       at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractSavePersistentMethod.doInvokeInternal(AbstractSavePersistentMethod.java:212) ~[grails-hibernate-2.1.2.jar:2.1.2]
       at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractDynamicPersistentMethod.invoke(AbstractDynamicPersistentMethod.java:63) ~[grails-hibernate-2.1.2.jar:2.1.2]
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_07]
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_07]
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_07]
       at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_07]
       at com.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1231) [springloaded-core-1.1.0.jar:1.0.0]
       at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189) ~[groovy-all-1.8.8.jar:1.8.8]
       at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53) ~[groovy-all-1.8.8.jar:1.8.8]
       at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) [groovy-all-1.8.8.jar:1.8.8]
       at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) [groovy-all-1.8.8.jar:1.8.8]
       at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124) [groovy-all-1.8.8.jar:1.8.8]
       at org.codehaus.groovy.grails.orm.hibernate.HibernateGormInstanceApi.save(HibernateGormEnhancer.groovy:909) ~[grails-hibernate-2.1.2.jar:2.1.2]
    

    初步故障排除表明传递给SaveOrUpdateEvent()及之后的(数据)源为空。

    我尝试将数据源显式添加为其他域对象的DEFAULT,但没有帮助。

    如果我只是注释掉dataSource_customer,则不会出现此异常。

0 个答案:

没有答案