0
當我保存與@multitenant註釋關聯的實例但沒有租戶時,Grails會發出此錯誤。所以我明確地嘗試使用Multitenant grails插件 - grails.plugin.multitenant.core.exception.NoCurrentTenantException
objInstance.setTenantId(tenantId)
把租戶ID拋出此異常:
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 ?????
'withTenantId'正常工作。如果您的域名有其他域名,請在'withTenantId'關閉內創建對象。 – user1690588
流是像我的控制器的行動得到調用,並在此控制器中,我們正在保存一個域名爲「objIntance1」現在我想創建和保存其他域類的新實例,說與objInstace1相同的租戶ID「objInstance」,當我標記保存objInstace它會給出錯誤。 org.springframework.orm.hibernate3.HibernateSystemException:非法嘗試將代理與兩個打開的會話相關聯;嵌套異常是org.hibernate.HibernateException:非法嘗試將代理與兩個打開的會話相關聯 –
您可以發佈您的代碼嗎? – user1690588