作业
class PicSchedulerJob {
def myDataService
def springSecurityService
static triggers = {
simple name:'picsJob', startDelay:1000,repeatInterval:30*60*1000
}
def group = "icsJobGroup"
def execute() {
def userList=User.list()
userList?.each{User user->
def fullList= Album.findAllByUser(user)
springSecurityService.reauthenticate(user.username)
fullList?.each{Album a->
myDataService.removePicsFilter( a)
}
}
}
}方法:
def removePicsFilter(Album a){
def tempList=a.photo
int siz=tempList.size()?:0
for(int i=0;i<siz;i++) {
Photo photodb=tempList[i]
PhotoConnection photoConnection=PhotoConnection.findByPhoto(photodb)
photoConnection?.tags.each{
Tag t=Tag.get(it.id)
t.delete()
}
}
a.save(validate:true,flush:true)
}错误:2013-12-06 20:20:59,618石英session _Worker-5 hibernate.LazyInitializationException错误-未能延迟初始化集合,没有会话或会话关闭org.hibernate.LazyInitializationException:未能延迟初始化集合,没有在org.hibernate.LazyInitializationException关闭会话或会话
作业是石英作业代码,方法代码由作业调用,它的错误是我所面临的错误。我也尝试用Album.withTransaction和Album.withSession的代码,但无法修复它。请在这个上指导我
发布于 2013-12-07 06:56:20
问题是,要么Hibernate会话未打开,要么已关闭。请通过链接http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/performance.html#performance-fetching-lazy
此外,对象可能与hibernate会话分离。你可以试试这个:
将对象附加回hibernate会话,如下所示: object.attach() (http://grails.org/doc/2.2.1/ref/Domain%20Classes/attach.html)使两个域类之间的关联不再懒惰(http://grails.org/doc/2.2.x/ref/Database%20Mapping/lazy.html)
发布于 2013-12-06 15:10:41
希望能帮上忙。
使用事务处理中的Hibernate.initialize()初始化延迟对象。
start Transaction
Hibernate.initialize(album.photo());
end Transaction
out of Transaction
tempList=album.photohttps://stackoverflow.com/questions/20427118
复制相似问题