Hibernate Grails-在插入之前访问域中的ServiceClass方法时出现空id错误

Hibernate Grails-在插入之前访问域中的ServiceClass方法时出现空id错误,hibernate,grails,Hibernate,Grails,在插入之前,我在我的域类中做了一些加密,效果很好。当我将代码移动到服务类时,尽管我得到了这个错误 | 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 unsa

在插入之前,我在我的域类中做了一些加密,效果很好。当我将代码移动到服务类时,尽管我得到了这个错误

| 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

SecurityService.groovy


你知道这是什么以及如何解决吗?如果重要的话,数据是通过BootStrap.groovy传入的,因为我还在测试

您是否在瞬态中定义了securityService?@injecteer-我没有,我的印象是,因为我使用的是'def',所以不需要将其添加到瞬态列表中。不,您在这一点上错了:默认情况下,只有静态字段和最终字段被排除在持久化之外。因此,您必须在transientsThanks@injecteer中再次定义注入的服务-我根据文档尝试了静态瞬态=['securityService'],但仍然得到相同的错误。我的域类中有几乎相同的代码,它工作得很好。张贴你的stacktrace的其余部分
class MyDomainClass {
    …
    String password

    static constraints = {
        …
    }

    def securityService
    static transients = ['securityService']

    def beforeInsert() {    
        password = securityService.encryptData(password)
    }
}
class SecurityService {
    def encryptData(plainText) {
        …
        return encryptedData
    }
}