I recently updated all my transaction definitions in spring to use annotations. Since, I've been getting an unusual exception whilst left joining onto the same entity. This occurs on the next (unrelated) call to hibernate. I'm guessing that previously the session was much shorter lived than now, therefore the object was detached from the session, preventing this flush.
Exception
Code:
Found shared references to a collection: com.traveljigsaw.pricing.businessObjects.TacticalPriceRule.experiments
org.hibernate.HibernateException: Found shared references to a collection: com.traveljigsaw.pricing.businessObjects.TacticalPriceRule.experiments
at org.hibernate.engine.Collections.processReachableCollection(Collections.java:185)
at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:60)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:122)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:83)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:77)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:165)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:58)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:890)
at com.traveljigsaw.pricing.dao.impl.BarrierDateDaoImpl.resolve(BarrierDateDaoImpl.java:84
Mapping
Code:
<hibernate-mapping>
<class name="com.traveljigsaw.pricing.businessObjects.TacticalPriceRule" table="TacticalPriceRule">
<id name="idTacticalPriceRule" type="java.lang.Integer">
<column name="idTacticalPriceRule"/>
<generator class="identity"/>
</id>
<property name="idExperiment" type="java.lang.Integer">
<column name="idExperiment" not-null="false" />
</property>
<set fetch="select" inverse="false" name="experiments">
<key property-ref="idExperiment">
<column name="idExperiment" not-null="false"/>
</key>
<one-to-many class="com.traveljigsaw.pricing.businessObjects.TacticalPriceRule"/>
</set> ...
HQL Query
Code:
select TPR from TacticalPriceRule as TPR
left join fetch TPR.experiments as TPRE
where TPR.variant is null or TPR.variant = 'A'
Any ideas or hints would be much appreciated,
Thanks,
Dan