Grails - 在Domain beforeInsert中访问ServiceClass方法时出现null id错误

时间:2014-08-31 16:36:48

标签: hibernate grails

我在我的域类beforeInsert中进行了一些加密,它运行得很好。当我将代码移动到服务类时,虽然我收到此错误

| Error 2014-09-01 10:33:50,229 [localhost-startStop-1] ERROR hibernate.AssertionFailure  - HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: null id in com.domain.MyDomainClass entry (don't flush the Session after an exception occurs)
| Error 2014-09-01 10:33:50,239 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: null id in com.domain.MyDomainClass entry (don't flush the Session after an exception occurs)
Message: null id in com.domain.MyDomainClass entry (don't flush the Session after an exception occurs)
    Line | Method
->>   35 | beforeInsert                     in com.domain.MyDomainClass
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    153 | call                             in org.grails.datastore.gorm.support.EventTriggerCaller$MethodCaller
|     96 | call . . . . . . . . . . . . . . in org.grails.datastore.gorm.support.EventTriggerCaller
|     47 | onApplicationEvent               in org.grails.datastore.mapping.engine.event.AbstractPersistenceEventListener
|      7 | doCall . . . . . . . . . . . . . in BootStrap$_closure1
|    327 | evaluateEnvironmentSpecificBlock in grails.util.Environment
|    320 | executeForEnvironment . . . . .  in     ''
|    296 | executeForCurrentEnvironment     in     ''
|    262 | run . . . . . . . . . . . . . .  in java.util.concurrent.FutureTask
|   1145 | runWorker                        in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                              in java.lang.Thread
| Error Forked Grails VM exited with error

MyDomainClass.groovy

class MyDomainClass {
    …
    String password

    static constraints = {
        …
    }

    def securityService
    static transients = ['securityService']

    def beforeInsert() {    
        password = securityService.encryptData(password)
    }
}

SecurityService.groovy

class SecurityService {
    def encryptData(plainText) {
        …
        return encryptedData
    }
}

任何想法是什么以及如何解决它?如果重要的话,数据是通过BootStrap.groovy传入的,因为我还在测试。

0 个答案:

没有答案