-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate upgrd 4.3.1-Found shared references to a colection
PostPosted: Mon Mar 31, 2014 4:50 pm 
Newbie

Joined: Wed Apr 24, 2013 4:32 pm
Posts: 2
We are working on Hibernate upgrade in my project. We were on hibernate 3.3.1, spring version 3.1.1 and working with JPA 2.0 as persistence layer. Now I am trying to upgrade Hibernate 4.3.1. we have done all necessary dependencies for this upgrade.

Able to build our project fine but when I run our JUnit tests, am getting Found shared references to a collection error (I have upgraded to Hibernate 4.3.1 with JPA 2.1 and Spring 3.1.1 in our project now). Can you please help me to solve this error .

Caused by: org.hibernate.HibernateException: Found shared references to a collection: com.carlson.cwt.portrait.domain.traveler.BusinessT raveler.addresses
at org.hibernate.engine.internal.Collections.processR eachableCollection(Collections.java:180)
at org.hibernate.event.internal.FlushVisitor.processC ollection(FlushVisitor.java:59)
at org.hibernate.event.internal.AbstractVisitor.proce ssValue(AbstractVisitor.java:121)
at org.hibernate.event.internal.AbstractVisitor.proce ssValue(AbstractVisitor.java:82)
at org.hibernate.event.internal.AbstractVisitor.proce ssEntityPropertyValues(AbstractVisitor.java:76)
at org.hibernate.event.internal.DefaultFlushEntityEve ntListener.onFlushEntity(DefaultFlushEntityEventLi stener.java:172)
at com.carlson.cwt.portrait.domain.event.ProfileEntit yFlushEventListener.onFlushEntity(ProfileEntityFlu shEventListener.java:37)
at org.hibernate.event.internal.AbstractFlushingEvent Listener.flushEntities(AbstractFlushingEventListen er.java:231)
at org.hibernate.event.internal.AbstractFlushingEvent Listener.flushEverythingToExecutions(AbstractFlush ingEventListener.java:102)
at org.hibernate.event.internal.DefaultAutoFlushEvent Listener.onAutoFlush(DefaultAutoFlushEventListener .java:61)
at org.hibernate.internal.SessionImpl.autoFlushIfRequ ired(SessionImpl.java:1187)
at org.hibernate.internal.SessionImpl.list(SessionImp l.java:1253)
at org.hibernate.internal.QueryImpl.list(QueryImpl.ja va:103)
at org.hibernate.jpa.internal.QueryImpl.list(QueryImp l.java:573)
at org.hibernate.jpa.internal.QueryImpl.getResultList (QueryImpl.java:449)
at org.springframework.orm.jpa.JpaTemplate$12.doInJpa (JpaTemplate.java:370)
at org.springframework.orm.jpa.JpaTemplate$12.doInJpa (JpaTemplate.java:1)
at org.springframework.orm.jpa.JpaTemplate.execute(Jp aTemplate.java:187)
... 42 more

My mappings are as below between BusinessTraveler and TravelerAddress:

in BusinessTraveler class:
@OneToMany (cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "businessTraveler")
private Set<TravelerAddress> addresses = new HashSet<TravelerAddress>();

in TravelerAddress class:
@ManyToOne
@JoinColumns ({
@JoinColumn (name = "BUSINESS_TRAVELER_ID", nullable = false, insertable = false, updatable = false),
@JoinColumn (name = "BUSINESS_TRAVELER_ORIG_ID", nullable = false, insertable = false, updatable = false) })
private BusinessTraveler businessTraveler;

Is this Found shared references to a collection occurs due to mappings? or because of some else in project??


Top
 Profile  
 
 Post subject: Re: Hibernate upgrd 4.3.1-Found shared references to a colection
PostPosted: Fri Dec 19, 2014 9:49 pm 
Newbie

Joined: Fri Oct 24, 2014 5:57 am
Posts: 2
Hi, did you ever determine what the problem was here?
We have same issue after hib upgrade


Top
 Profile  
 
 Post subject: Re: Hibernate upgrd 4.3.1-Found shared references to a colection
PostPosted: Mon Dec 29, 2014 4:23 am 
Newbie

Joined: Sun Jun 03, 2007 5:01 pm
Posts: 6
One way this can happen is when your code has somehow tried to share the same collection object reference between two different entities instances.

eg:
masterTwo.setSlaves( masterOne.getSlaves() );

In your case, it would imply using the same Set object from one BusinessTraveller instance in another BusinessTraveller instance.

However, that would throw the exception at commit time, and looking at your stack trace it appears to be occuring when hibernate is reconstituting the objects to return to you as query results.

This suggests that maybe the old data you are running the unit tests against contains values for your composite foreign key which are 'bad'?

Unfortunately I'm not really familiar enough with the JPA annotions to make good suggestions about what exactly to look for in that case.

I did notice docs for @JoinColumns which state: "When the JoinColumns annotation is used, both the name and the referencedColumnName elements must be specified in each such JoinColumn annotation. ".

You aren't specifying the referencedColumn in the annotations, I think implying both FK columns in your composite FK would refer to the PK of BusinessTraveller? - which doesn't quite make sense since only one BusinessTraveller can own a particular TravellerAdress entity as it is a One BusinessTraveller to Many TravellerAddress relationship and if they refer to different BusinessTravellers... that wouldnt make sense for a OneToMany/ManyToOne.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.