多租户 grails 插件 - grails.plugin.multitenant.core.exception.NoCurrentTenantException
Multitenant grails plugin - grails.plugin.multitenant.core.exception.NoCurrentTenantException
Grails 在我保存一个与@multitenant 注释关联但没有租户存在的实例时出现此错误。所以我明确地尝试使用
放置租户 ID
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);
} */
}
}
不明白如何保存那个objInsatance ????
使用合并而不是保存。 objInstance?.merge();
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 ????
使用合并而不是保存。 objInstance?.merge();