a)我尝试保存属于数据存储域类的联系人项目,如下所示:
class Contacts implements Serializable{
static belongsTo = [dataStore:DataStore]
DataStore dataStore
String emailaddress
DS 类:
class DataStore implements Serializable{
static belongsTo = [service:Service,user:User]
static hasMany = [users:User,contacts:Contacts,groups:Groups]
Service service
User user
User users
List<Contacts> contacts
b)在控制器级别,我创建一个联系人作为 ajax 请求:
def create() {
String key = session["KEY"]
DataStore ds = session["DS"]
def user = springSecurityService.currentUser
def c = new Contacts(dataStore:ds,emailaddress:params.contacts.email)
if (c.validate()) {
ds.addToContacts(c).save(flush:true)
c.save()
c) 以下错误阻止了保存
failed to lazily initialize a collection of role: $$$.DataStore.contacts, no session or session was closed. Stacktrace follows:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: $$$.DataStore.contacts, no session or session was closed
at $$$$.ContactsController$$EO4iccbg.create(ContactsController.groovy:115)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:149)
at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:259)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:202)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:175)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)
会话处于活动状态...这是什么意思?有什么想法可以解决这个问题吗?谢谢