-->
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.  [ 1 post ] 
Author Message
 Post subject: "Found shared references to a collection" misbehav
PostPosted: Thu Sep 30, 2004 10:51 am 
Newbie

Joined: Tue Apr 13, 2004 6:41 am
Posts: 19
Hibernate version:
2.1.6
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="test.pure.model" default-cascade="save-update">
<class name="AccountPure" discriminator-value="507108503" optimistic-lock="version" dynamic-update="true">
<id name="id" access="field">
<generator class="assigned"></generator>
</id>
<discriminator/>
<version name="version" access="field" unsaved-value="null"/>
<property name="number" access="field"/>
<property name="description" access="field"/>
<many-to-one name="person" class="test.pure.model.PersonPure" access="field" column="person_id"/>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="test.pure.model" default-cascade="save-update">
<class name="AddressPure" discriminator-value="507108503" optimistic-lock="version" dynamic-update="true">
<id name="id" access="field">
<generator class="assigned"></generator>
</id>
<discriminator/>
<version name="version" access="field" unsaved-value="null"/>
<property name="street" access="field"/>
<property name="zip" access="field"/>
<many-to-one name="person" class="test.pure.model.PersonPure" access="field" column="person_id"/>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="test.pure.model" default-cascade="save-update">
<class name="PersonPure" discriminator-value="507108503" optimistic-lock="version" dynamic-update="true">
<id name="id" access="field">
<generator class="assigned"></generator>
</id>
<discriminator/>
<version name="version" access="field" unsaved-value="null"/>
<property name="firstName" access="field"/>
<property name="lastName" access="field"/>
<set name="addresses" lazy="true" access="field" inverse="true">
<key column="person_id"/>
<one-to-many class="test.pure.model.AddressPure"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

try {
{
Session s = sf.openSession();
Query q = s.createQuery("from AccountPure");
AccountPure account1 = (AccountPure)q.iterate().next();
s.close();

s = sf.openSession();
s.lock(account1,LockMode.NONE);
Transaction tx = s.beginTransaction();

Set addresses1 = account1.getPerson().getAddresses();
PersonPure person1 = new PersonPure();
person1.setId(getNextId());
person1.setFirstName("name"+getNextId());
person1.setAddresses(addresses1);
account1.setPerson(person1);

tx.commit();

}

} catch (HibernateException e) {
e.printStackTrace();
}


Gives exception:

net.sf.hibernate.HibernateException: Found shared references to a collection: test.pure.model.PersonPure.addresses
at net.sf.hibernate.impl.SessionImpl.updateReachableCollection(SessionImpl.java:2875)
at net.sf.hibernate.impl.FlushVisitor.processCollection(FlushVisitor.java:32)
at net.sf.hibernate.impl.AbstractVisitor.processValue(AbstractVisitor.java:69)
at net.sf.hibernate.impl.AbstractVisitor.processValues(AbstractVisitor.java:36)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2592)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2458)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2260)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2239)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at test.pure.TestRunner.lock(TestRunner.java:73)
at test.pure.TestRunner.main(TestRunner.java:39)

I am trying to save only 1 person and my intent is to replace owner of addresses (not to share them between these 2 persons).
Is there any option that I can set (in mapping or otherwise) so constraints like these are silently ignored?
Because doing account1.getPerson().setAddresses(null); before I am setting same addresses to another person is pretty much redundant in this case??

Rihards


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

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.