cuba-platform / cuba

CUBA Platform is a high level framework for enterprise applications development
https://www.cuba-platform.com
Apache License 2.0
1.34k stars 219 forks source link

EntityLog throw exception when logging entity from additional datastore #3208

Open ym-rgalimov opened 3 years ago

ym-rgalimov commented 3 years ago

Environment

Description of the bug or enhancement

Hi Team,

In my project I have additional datastore configured. We have EntityLog setup to track changes for entities from this datastore. When I'm trying to delete entity, it removes entity as expected. But I see an exception in the log on registering changes and changes don't track.

It looks like EL trying to traverse all properties in entity and when it come across on entity relation it cannot load it.

Entity (in additional store):

@NamePattern("%s|name")
@Table(name = "campaign")
@Entity(name = "ymcuba$Campaign")
public class Campaign extends BaseUniqueIdEntity implements SoftDelete {

  ...

  @OnDelete(DeletePolicy.CASCADE)
  @OneToOne(fetch = FetchType.LAZY, mappedBy = "campaign", cascade = CascadeType.PERSIST)
  protected CampaignBudget budget;

  ...

  public void setBudget(CampaignBudget budget) {
    this.budget = budget;
  }

  public CampaignBudget getBudget() {
    return budget;
  }

  ...

}

Stacktrace:

java.lang.IllegalStateException: Cannot handle entity from ADSTORE datastore because active transaction is for _MAIN_
    at com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport.getInstanceContainerResourceHolder(PersistenceImplSupport.java:182) ~[cuba-core-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport.registerInstance(PersistenceImplSupport.java:151) ~[cuba-core-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.core.sys.persistence.EclipseLinkDescriptorEventListener.postClone(EclipseLinkDescriptorEventListener.java:105) ~[cuba-core-7.2.13.jar:7.2.13]
    at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.java:728) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListeners(DescriptorEventManager.java:767) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at org.eclipse.persistence.descriptors.DescriptorEventManager.executeEvent(DescriptorEventManager.java:232) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at com.haulmont.cuba.core.sys.persistence.DescriptorEventManagerWrapper.executeEvent(DescriptorEventManagerWrapper.java:183) ~[cuba-core-7.2.13.jar:7.2.13]
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeDeferredEvents(AbstractSession.java:1528) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:3021) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1892) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1874) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:161) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:124) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:107) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiateImpl(UnitOfWorkValueHolder.java:176) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:237) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:107) ~[org.eclipse.persistence.core-2.7.3-14-cuba.jar:na]
    at com.company.cuba.entity.Campaign._persistence_get_budget(Campaign.java) ~[app-global-0.1-SNAPSHOT.jar:na]
    at com.company.cuba.entity.Campaign.getBudget(Campaign.java:462) ~[app-global-0.1-SNAPSHOT.jar:na]
    at com.haulmont.chile.core.model.impl.AbstractInstance.getValue(AbstractInstance.java:108) ~[cuba-global-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.core.entity.BaseGenericIdEntity.getValue(BaseGenericIdEntity.java:146) ~[cuba-global-7.2.13.jar:7.2.13]
    at com.haulmont.chile.core.model.utils.InstanceUtils.getValueEx(InstanceUtils.java:159) ~[cuba-global-7.2.13.jar:7.2.13]
    at com.haulmont.chile.core.model.utils.InstanceUtils.getValueEx(InstanceUtils.java:121) ~[cuba-global-7.2.13.jar:7.2.13]
    at com.haulmont.chile.core.model.impl.AbstractInstance.getValueEx(AbstractInstance.java:166) ~[cuba-global-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.security.app.EntityLog.createLogAttributes(EntityLog.java:639) ~[cuba-core-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.security.app.EntityLog.internalRegisterDelete(EntityLog.java:759) ~[cuba-core-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.security.app.EntityLog.registerDelete(EntityLog.java:733) ~[cuba-core-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport$OnSaveEntityVisitor.visit(PersistenceImplSupport.java:564) ~[cuba-core-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport.beforeStore(PersistenceImplSupport.java:237) ~[cuba-core-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport.traverseEntities(PersistenceImplSupport.java:223) ~[cuba-core-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport$ContainerResourceSynchronization.beforeCommit(PersistenceImplSupport.java:409) ~[cuba-core-7.2.13.jar:7.2.13]
    at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:96) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:919) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:727) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at com.haulmont.cuba.core.sys.TransactionImpl.commit(TransactionImpl.java:104) ~[cuba-core-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.core.app.RdbmsStore.commit(RdbmsStore.java:561) ~[cuba-core-7.2.13.jar:7.2.13]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:62) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at com.sun.proxy.$Proxy662.commit(Unknown Source) ~[na:na]
    at com.haulmont.cuba.core.app.DataManagerBean.commit(DataManagerBean.java:188) ~[cuba-core-7.2.13.jar:7.2.13]
    at com.haulmont.cuba.core.app.DataServiceBean.commit(DataServiceBean.java:41) ~[cuba-core-7.2.13.jar:7.2.13]