【发布时间】:2015-08-07 18:50:58
【问题描述】:
当我保存与@multitenant 注释关联但没有租户存在的实例时,Grails 给出此错误。所以我明确地尝试使用
objInstance.setTenantId(tenantId)
抛出此异常:
grails.plugin.multitenant.core.exception.NoCurrentTenantException: Tried to save multi-tenant domain class 'objInstance', but no tenant is set
当我使用时
Customer.withTenantId(tenantId){ objInstance.save(flush:true) }
然后它抛出这个异常:
org.springframework.orm.hibernate3.HibernateSystemException: illegally attempted to associate a proxy with two open Sessions; nested exception is org.hibernate.HibernateException: illegally attempted to associate a proxy with two open Sessions
控制器代码:
def myservice
def myAction(MOrder objInstance1){
objInstance1.properties = params;
objInstance1?.save(flush:true)
myservice.callingMyserviceMEthod(objInstance1)
}
服务代码:
def callingMyserviceMEthod(MOrder objInstance1){
objInstance1.setOrderProcess(true);
objInstance1?.save(flush:true);
if(objInstance1.getOrderProcess()){
// creating new object object of POrder as objInstance1
POrder objInstance = new POrder();
objInstance?.setName("ABC");
objInstance?.setOrderStatus("process");
objInstance?.setTenantId(objInstance1?.getTenantId());
objInstance?.save(flush:true);
// I also tried this code with Customer.withTenantId()
/*
Customer.withTenantId(){
POrder objInstance = new POrder();
objInstance?.setName("ABC");
objInstance?.setOrderStatus("process");
objInstance?.save(flush:true);
} */
}
}
不明白如何保存那个 objInstance ?????
【问题讨论】:
-
withTenantId工作正常。如果您的域有其他域,则在withTenantId闭包中创建您的对象。 -
流程就像我的控制器的动作被调用并且在这个控制器中我们正在保存一个域说“objIntance1”现在我想创建并保存一个其他域类的新实例说“objInstance” objInstace1 的租户 ID,当我标记保存 objInstace 时,它会出错。 org.springframework.orm.hibernate3.HibernateSystemException:非法尝试将代理与两个打开的会话关联;嵌套异常是 org.hibernate.HibernateException: 非法尝试将代理与两个打开的会话关联
-
你能发布你的代码吗?
-
是的,我现在粘贴了带有问题的示例代码
标签: hibernate grails grails-plugin multi-tenant