Grails在保存与@multitenant注释关联但不存在租户的实例时发出此错误。所以我明确尝试使用
来设置租户IDobjInstance.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);
} */
}
}
不明白如何保存objInsatance ?????
答案 0 :(得分:1)
使用merge而不是save。 objInstance .merge();