gpt4 book ai didi

grails - Grails “don' t在发生异常后刷新 session ”错误消息

转载 作者:行者123 更新时间:2023-12-02 14:15:33 25 4
gpt4 key购买 nike

我看到此错误消息已经在休眠环境中发布了好几次。

使用grails服务和域类时遇到此错误,我们将不胜感激

域类

class Coupon {
Date dateCreated
Date lastUpdated
String code
String email
String address
String state
String city
String zip
def couponCodeGeneratorService

def beforeValidate() {
println code+"---------8-"
code = couponCodeGeneratorService.generate()
println code+"----------"
}
static constraints = {
email blank:false,email:true
address blank:false
state blank:false
city blank:false
zip blank:false
}
}

服务
class CouponCodeGeneratorService {
Random randomGenerator = new Random()
def serviceMethod() {

}
def generate(){
def group1 = randomGenerator.nextInt(9999)+"";
def group2 = randomGenerator.nextInt(9999)+"";
def group3 = randomGenerator.nextInt(9999)+"";
def group4 = randomGenerator.nextInt(9999)+"";
return group1.padLeft(4,"0") +group2.padLeft(4,"0")+group3.padLeft(4,"0")+group4.padLeft(4,"0")
}
}

我得到的错误是
---------8-
4844634041715590----------
4844634041715590---------8-
| Error 2012-09-10 11:32:54,938 [http-bio-8080-exec-7] ERROR hibernate.AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
Message: null id in com.easytha.Coupon entry (don't flush the Session after an exception occurs)
Line | Method
->> 19 | beforeValidate in com.easytha.Coupon
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 46 | onApplicationEvent in org.grails.datastore.mapping.engine.event.AbstractPersistenceEventListener
| 24 | save . . . . . . . in com.easytha.CouponController
| 186 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . . . . . in grails.plugin.cache.web.filter.AbstractFilter
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . . . . . . in ''
^ 662 | run in java.lang.Thread
| Error 2012-09-10 11:32:54,944 [http-bio-8080-exec-7] ERROR errors.GrailsExceptionResolver - AssertionFailure occurred when processing request: [POST] /EasyTha/coupon/save - parameters:
zip: asdf
address: asd
email: s.s@s.xom
state: asd
code:
create: Create
city: asdf
null id in com.easytha.Coupon entry (don't flush the Session after an exception occurs). Stacktrace follows:
Message: null id in com.easytha.Coupon entry (don't flush the Session after an exception occurs)
Line | Method
->> 19 | beforeValidate in com.easytha.Coupon
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 46 | onApplicationEvent in org.grails.datastore.mapping.engine.event.AbstractPersistenceEventListener
| 24 | save . . . . . . . in com.easytha.CouponController
| 186 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . . . . . in grails.plugin.cache.web.filter.AbstractFilter
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . . . . . . in ''
^ 662 | run in java.lang.Thread

我对Hibernate不太熟悉,这也是创建看起来像信用卡号的优惠券代码的正确方法吗?

最佳答案

我怀疑问题可能在于CouponCodeGeneratorService是事务性的。因此,当您从beforeValidate内部调用服务方法时,您正在打开和关闭事务(即使您没有触摸该方法内部的数据库),这将导致 session 的另一次刷新。

尝试使服务成为非事务性服务:

static transactional = false

关于grails - Grails “don' t在发生异常后刷新 session ”错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12342373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com