Hi,
I'm reading in a graph using SQL and then constructing my java objects from the
results. I would like to then add the newly instantiated objects to the cache
using lock(). I've included the @Cascade(CascadeType.LOCK) to the associations,
but I'm getting a dirty collection error. It seems that when it looks at the
collection downstreamStatusValues, the OnLockVisitor class determines that
collection is not an instance of PersistentCollection. Can anyone help me
understand what the problem is?
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@Table(name="SHM_HEALTHVALUE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@DiscriminatorColumn(
name="HEALTHTYPE",
discriminatorType=DiscriminatorType.INTEGER
)
public abstract class HealthValue extends BaseObject {
protected Collection<HealthStatusValue> downstreamStatusValues;
@ManyToMany
@Cascade(CascadeType.LOCK)
public Collection<HealthStatusValue> getDownstreamStatusValues() {
return this.downstreamStatusValues;
}
}
Code:
Entity
@DiscriminatorValue(HealthType.HEALTH_STATUS_ORDINAL)
public class HealthStatusValue extends HealthValue {
// the children
private Collection<HealthStatusValue> upstreamStatusValues;
private Collection<HealthFactorValue> factorValues;
@ManyToMany(mappedBy="downstreamStatusValues")
@Cascade(CascadeType.LOCK)
public Collection<HealthFactorValue> getFactorValues() {
return this.factorValues;
}
@ManyToMany (mappedBy="downstreamStatusValues")
@Cascade(CascadeType.LOCK)
public Collection<HealthStatusValue> getUpstreamStatusValues() {
return this.upstreamStatusValues;
}
Code:
@Entity
@DiscriminatorValue(HealthType.HEALTH_FACTOR_ORDINAL)
public class HealthFactorValue extends HealthValue {
}
Hibernate version: 3.2
Full stack trace of any exception that occurs:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CalcEngineBeanContainer' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'HealthCE' while setting bean property 'ceComponents' with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HealthCE' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'GraphManager' while setting bean property 'graphManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'GraphManager' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: reassociated object has dirty collection reference (or an array)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HealthCE' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'GraphManager' while setting bean property 'graphManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'GraphManager' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: reassociated object has dirty collection reference (or an array)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'GraphManager' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: reassociated object has dirty collection reference (or an array)
Caused by: org.hibernate.HibernateException: reassociated object has dirty collection reference (or an array)
at org.hibernate.event.def.OnLockVisitor.processCollection(OnLockVisitor.java:66)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)
at org.hibernate.event.def.AbstractReassociateEventListener.reassociate(AbstractReassociateEventListener.java:78)
at org.hibernate.event.def.DefaultLockEventListener.onLock(DefaultLockEventListener.java:59)
at org.hibernate.impl.SessionImpl.fireLock(SessionImpl.java:586)
at org.hibernate.impl.SessionImpl.lock(SessionImpl.java:578)
at com.hp.ov.shm.healthce.dao.hibernate.HealthStatusGraphDaoHibernate.lock(HealthStatusGraphDaoHibernate.java:122)
at com.hp.ov.shm.healthce.impl.GraphManager.init_aroundBody0(GraphManager.java:349)
at com.hp.ov.shm.healthce.impl.GraphManager.init_aroundBody1$advice(GraphManager.java:854)
at com.hp.ov.shm.healthce.impl.GraphManager.init(GraphManager.java:1)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:943)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:905)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:870)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:393)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:257)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:168)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:226)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:115)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:798)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:589)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:389)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:257)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:168)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:226)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:115)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:242)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:119)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:798)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:589)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:389)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:257)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:168)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:254)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:332)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
at org.springframework.test.AbstractSpringContextTests.loadContextLocations(AbstractSpringContextTests.java:130)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.loadContextLocations(AbstractDependencyInjectionSpringContextTests.java:224)
at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:110)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.setUp(AbstractDependencyInjectionSpringContextTests.java:192)
at junit.framework.TestCase.runBare(TestCase.java:128)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)