-->
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.  [ 10 posts ] 
Author Message
 Post subject: all-delete-orphan exception when only adding new objects?
PostPosted: Thu Mar 04, 2004 4:37 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
Hello,

I am trying to save() a new object that has a collection of other new objects. I have all-delete-orphan between parent and child. When I try to save() the parent, I always receive the "You may not dereference a collection with cascade="all-delete-orphan"" exception. I understand why I can't do that, but not sure why I'm getting this error here.

The code below shows what's happening. I create a new parent, then a new child, then add the child to the parent, then save(). When I add the child, I have to add it into a collection. Because the parent is new (not controlled by hibernate) its collection to hold the children is null, so I have to create a new collection. I believe here is where it breaks, but I don't think it should break. Of course, I could be using it wrong.

Person person = new Person();
person.addAddress(new Address());
dao.save(person);

I bind the child to the parent with this logic:

public void addAddress(Address address) {
if (addresses == null) {
addresses = new HashSet();
}

// make idempotent

for (Iterator i = getAddresses().iterator(); i.hasNext();) {
Address addr = (Address) i.next();

if (addr.getType() != null &&
addr.getType().equals(address.getType())) {
i.remove();
}
}

addresses.add(address);
}

The mapping:

<set
name="addresses"
lazy="true"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted">

<key column="person_id" />

<one-to-many class="com.hic.core.Address" />
</set>


I'm using:

- hibernate 2.1
- Mysql 4, linux 2.6, jdk 1.4

Any ideas on how to handle this case? I think hibernate thinks I dereferenced the collection because I had to do a new HashSet() there. How else would I save a graph of new objects?

Thanks very much!
Seth


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 4:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
From the test suite:

Code:
   public void testOrphanDelete() throws Exception {
      Session s = openSession();
      Transaction t = s.beginTransaction();
      Baz baz = new Baz();
      Set bars = new HashSet();
      baz.setCascadingBars(bars);
      bars.add( new Bar() );
      bars.add( new Bar() );
      bars.add( new Bar() );
      bars.add( new Bar() );
      s.save(baz);
      t.commit();
      s.close();



How about a stack trace, perhaps even a Hibernate log.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 4:51 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
Great, thanks. I'm glad it's just my setup. I'm sure Hibernate could do this.

Exception:

2004-03-04 10:47:18 StandardContext[/eBOSS]Problem committing txn, attempting rollback
net.sf.hibernate.HibernateException: You may not dereference a collection with cascade="all-delete-orphan"
at net.sf.hibernate.impl.SessionImpl.updateUnreachableCollection(SessionImpl.java:2803)
at net.sf.hibernate.impl.SessionImpl.flushCollections(SessionImpl.java:2672)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2208)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2186)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.hic.core.dao.SessionManagerImpl.commitTransaction(Unknown Source)
at com.hic.web.SessionManagerFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at com.hic.web.ChooseContentTypeFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 4:52 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
Sorry, but where do I find the Hibernate log?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 4:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ah hah! So, looks like a broken get/set pair, doesn't it!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 5:00 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
Not sure exactly what you mean. I changed the code to this and I still see the problem:

public void addAddress(Address address) {
if (getAddresses() == null) {
setAddresses(new HashSet());
}

// make idempotent

for (Iterator i = getAddresses().iterator(); i.hasNext();) {
Address addr = (Address) i.next();

if (addr.getType() != null &&
addr.getType().equals(address.getType())) {
i.remove();
}
}

addresses.add(address);
}


Top
 Profile  
 
 Post subject: The Debug Log
PostPosted: Thu Mar 04, 2004 5:21 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
Sorry for the verbosity:

[DEBUG,net.sf.hibernate.impl.SessionImpl] opened session
[DEBUG,net.sf.hibernate.impl.SessionImpl] loading [com.hic.eboss.Business#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.SessionImpl] attempting to resolve [com.hic.eboss.Business#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.SessionImpl] object not resolved in any cache [com.hic.eboss.Business#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.persister.EntityPersister] Materializing entity: [com.hic.eboss.Business#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.SQL] select business0_.id as id2_, business0_.name as name2_, business0_.type as type2_, business0_.description as descript4_2_, business0_.state as state2_, business0_.person_id as person_id2_, employment1_.id as id0_, employment1_.employees as employees0_, employment1_.beganEmployment as beganEmp3_0_, employment1_.firstWagesPaid as firstWag4_0_, person2_.id as id1_, person2_.firstName as firstName1_, person2_.lastName as lastName1_ from BUSINESS business0_ left outer join EMPLOYMENT employment1_ on business0_.id=employment1_.id left outer join PERSON person2_ on business0_.person_id=person2_.id where business0_.id=?
Hibernate: select business0_.id as id2_, business0_.name as name2_, business0_.type as type2_, business0_.description as descript4_2_, business0_.state as state2_, business0_.person_id as person_id2_, employment1_.id as id0_, employment1_.employees as employees0_, employment1_.beganEmployment as beganEmp3_0_, employment1_.firstWagesPaid as firstWag4_0_, person2_.id as id1_, person2_.firstName as firstName1_, person2_.lastName as lastName1_ from BUSINESS business0_ left outer join EMPLOYMENT employment1_ on business0_.id=employment1_.id left outer join PERSON person2_ on business0_.person_id=person2_.id where business0_.id=?
[DEBUG,net.sf.hibernate.impl.BatcherImpl] preparing statement
[DEBUG,net.sf.hibernate.type.StringType] binding '402801e6fb177bcc00fb177e141d0001' to parameter: 1
[DEBUG,net.sf.hibernate.loader.Loader] processing result set
[DEBUG,net.sf.hibernate.type.StringType] returning null as column: id0_
[DEBUG,net.sf.hibernate.type.StringType] returning null as column: id1_
[DEBUG,net.sf.hibernate.loader.Loader] result row: null, null, 402801e6fb177bcc00fb177e141d0001
[DEBUG,net.sf.hibernate.loader.Loader] Initializing object from ResultSet: 402801e6fb177bcc00fb177e141d0001
[DEBUG,net.sf.hibernate.loader.Loader] Hydrating entity: com.hic.eboss.Business#402801e6fb177bcc00fb177e141d0001
[DEBUG,net.sf.hibernate.type.StringType] returning 'sadfadf' as column: name2_
[DEBUG,net.sf.hibernate.type.PersistentEnumType] returning '0' as column: type2_
[DEBUG,net.sf.hibernate.type.StringType] returning 'asdfsad' as column: descript4_2_
[DEBUG,net.sf.hibernate.type.PersistentEnumType] returning '0' as column: state2_
[DEBUG,net.sf.hibernate.type.StringType] returning null as column: person_id2_
[DEBUG,net.sf.hibernate.loader.Loader] done processing result set (1 rows)
[DEBUG,net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.impl.BatcherImpl] closing statement
[DEBUG,net.sf.hibernate.loader.Loader] total objects hydrated: 1
[DEBUG,net.sf.hibernate.impl.SessionImpl] resolving associations for [com.hic.eboss.Business#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.SessionImpl] collection not cached
[DEBUG,net.sf.hibernate.impl.SessionImpl] collection not cached
[DEBUG,net.sf.hibernate.impl.SessionImpl] loading [com.hic.eboss.Employment#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.SessionImpl] attempting to resolve [com.hic.eboss.Employment#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.SessionImpl] collection not cached
[DEBUG,net.sf.hibernate.impl.SessionImpl] done materializing entity [com.hic.eboss.Business#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.SessionImpl] initializing non-lazy collections
[DEBUG,net.sf.hibernate.transaction.JDBCTransaction] begin
[DEBUG,net.sf.hibernate.transaction.JDBCTransaction] current autocommit status:false
[DEBUG,net.sf.hibernate.impl.SessionImpl] object already associated with session
[DEBUG,net.sf.hibernate.impl.SessionImpl] flushing session
[DEBUG,net.sf.hibernate.engine.Cascades] processing cascades for: com.hic.eboss.Business
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to collection: com.hic.eboss.Business.addresses
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to collection: com.hic.eboss.Business.phoneNumbers
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to saveOrUpdate()
[DEBUG,net.sf.hibernate.impl.SessionImpl] saveOrUpdate() unsaved instance
[DEBUG,net.sf.hibernate.impl.SessionImpl] saving [com.hic.core.Person#402801e6fb17be2200fb17bf2d2c0003]
[DEBUG,net.sf.hibernate.engine.Cascades] processing cascades for: com.hic.core.Person
[DEBUG,net.sf.hibernate.engine.Cascades] done processing cascades for: com.hic.core.Person
[DEBUG,net.sf.hibernate.engine.Cascades] processing cascades for: com.hic.core.Person
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to collection: com.hic.core.Person.phoneNumbers
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to saveOrUpdate()
[DEBUG,net.sf.hibernate.impl.SessionImpl] saveOrUpdate() unsaved instance
[DEBUG,net.sf.hibernate.impl.SessionImpl] saving [com.hic.core.Phone#402801e6fb17be2200fb17bf2d2d0004]
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to collection: com.hic.core.Person.addresses
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to saveOrUpdate()
[DEBUG,net.sf.hibernate.impl.SessionImpl] saveOrUpdate() unsaved instance
[DEBUG,net.sf.hibernate.impl.SessionImpl] saving [com.hic.core.Address#402801e6fb17be2200fb17bf2d2d0005]
[DEBUG,net.sf.hibernate.engine.Cascades] done processing cascades for: com.hic.core.Person
[DEBUG,net.sf.hibernate.engine.Cascades] done processing cascades for: com.hic.eboss.Business
[DEBUG,net.sf.hibernate.impl.SessionImpl] Flushing entities and processing referenced collections
[DEBUG,net.sf.hibernate.persister.AbstractEntityPersister] com.hic.eboss.Business.localContact is dirty
[DEBUG,net.sf.hibernate.impl.SessionImpl] Updating entity: [com.hic.eboss.Business#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.SessionImpl] Collection found: [com.hic.eboss.Business.activities#402801e6fb177bcc00fb177e141d0001], was: [com.hic.eboss.Business.activities#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.SessionImpl] Collection found: [com.hic.eboss.Business.addresses#402801e6fb177bcc00fb177e141d0001], was: [com.hic.eboss.Business.addresses#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.SessionImpl] Collection found: [com.hic.eboss.Business.phoneNumbers#402801e6fb177bcc00fb177e141d0001], was: [com.hic.eboss.Business.phoneNumbers#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.WrapVisitor] Wrapped collection in role: com.hic.core.Person.phoneNumbers
[DEBUG,net.sf.hibernate.impl.WrapVisitor] Wrapped collection in role: com.hic.core.Person.addresses
[DEBUG,net.sf.hibernate.impl.SessionImpl] Collection found: [com.hic.core.Person.phoneNumbers#402801e6fb17be2200fb17bf2d2c0003], was: [<unreferenced>]
[DEBUG,net.sf.hibernate.impl.SessionImpl] Collection found: [com.hic.core.Person.addresses#402801e6fb17be2200fb17bf2d2c0003], was: [<unreferenced>]
[DEBUG,net.sf.hibernate.impl.SessionImpl] Processing unreferenced collections
[DEBUG,net.sf.hibernate.impl.SessionImpl] Scheduling collection removes/(re)creates/updates
[DEBUG,net.sf.hibernate.impl.SessionImpl] Flushed: 3 insertions, 1 updates, 0 deletions to 4 objects
[DEBUG,net.sf.hibernate.impl.SessionImpl] Flushed: 2 (re)creations, 0 updates, 0 removals to 5 collections
[DEBUG,net.sf.hibernate.impl.Printer] listing entities:
[DEBUG,net.sf.hibernate.impl.Printer] com.hic.eboss.Business{addresses=uninitialized, phoneNumbers=uninitialized, type=0, employment=null, activities=uninitialized, description=asdfsad, state=0, localContact=Person#402801e6fb17be2200fb17bf2d2c0003, name=sadfadf, id=402801e6fb177bcc00fb177e141d0001}
[DEBUG,net.sf.hibernate.impl.Printer] com.hic.core.Person{addresses=[], phoneNumbers=[], firstName=asdf, id=402801e6fb17be2200fb17bf2d2c0003, lastName=asdfsadf}
[DEBUG,net.sf.hibernate.impl.Printer] com.hic.core.Address{street2=, country=ARM, street1=asdfasdf, type=physical, state=AL, zip=asdf, city=asdfasdf, id=402801e6fb17be2200fb17bf2d2d0005}
[DEBUG,net.sf.hibernate.impl.Printer] com.hic.core.Phone{extension=, areaCode=, type=business, suffix=4444, prefix=333, id=402801e6fb17be2200fb17bf2d2d0004}
[DEBUG,net.sf.hibernate.impl.SessionImpl] executing flush
[DEBUG,net.sf.hibernate.persister.EntityPersister] Inserting entity: [com.hic.core.Person#402801e6fb17be2200fb17bf2d2c0003]
[DEBUG,net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.SQL] insert into PERSON (firstName, lastName, id) values (?, ?, ?)
Hibernate: insert into PERSON (firstName, lastName, id) values (?, ?, ?)
[DEBUG,net.sf.hibernate.impl.BatcherImpl] preparing statement
[DEBUG,net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.hic.core.Person#402801e6fb17be2200fb17bf2d2c0003]
[DEBUG,net.sf.hibernate.type.StringType] binding 'asdf' to parameter: 1
[DEBUG,net.sf.hibernate.type.StringType] binding 'asdfsadf' to parameter: 2
[DEBUG,net.sf.hibernate.type.StringType] binding '402801e6fb17be2200fb17bf2d2c0003' to parameter: 3
[DEBUG,net.sf.hibernate.persister.EntityPersister] Inserting entity: [com.hic.core.Phone#402801e6fb17be2200fb17bf2d2d0004]
[DEBUG,net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.impl.BatcherImpl] closing statement
[DEBUG,net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.SQL] insert into PHONE (areaCode, prefix, suffix, extension, type, id) values (?, ?, ?, ?, ?, ?)
Hibernate: insert into PHONE (areaCode, prefix, suffix, extension, type, id) values (?, ?, ?, ?, ?, ?)
[DEBUG,net.sf.hibernate.impl.BatcherImpl] preparing statement
[DEBUG,net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.hic.core.Phone#402801e6fb17be2200fb17bf2d2d0004]
[DEBUG,net.sf.hibernate.type.StringType] binding '' to parameter: 1
[DEBUG,net.sf.hibernate.type.StringType] binding '333' to parameter: 2
[DEBUG,net.sf.hibernate.type.StringType] binding '4444' to parameter: 3
[DEBUG,net.sf.hibernate.type.StringType] binding '' to parameter: 4
[DEBUG,net.sf.hibernate.type.StringType] binding 'business' to parameter: 5
[DEBUG,net.sf.hibernate.type.StringType] binding '402801e6fb17be2200fb17bf2d2d0004' to parameter: 6
[DEBUG,net.sf.hibernate.persister.EntityPersister] Inserting entity: [com.hic.core.Address#402801e6fb17be2200fb17bf2d2d0005]
[DEBUG,net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.impl.BatcherImpl] closing statement
[DEBUG,net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.SQL] insert into ADDRESS (street1, street2, city, state, zip, type, country, id) values (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into ADDRESS (street1, street2, city, state, zip, type, country, id) values (?, ?, ?, ?, ?, ?, ?, ?)
[DEBUG,net.sf.hibernate.impl.BatcherImpl] preparing statement
[DEBUG,net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.hic.core.Address#402801e6fb17be2200fb17bf2d2d0005]
[DEBUG,net.sf.hibernate.type.StringType] binding 'asdfasdf' to parameter: 1
[DEBUG,net.sf.hibernate.type.StringType] binding '' to parameter: 2
[DEBUG,net.sf.hibernate.type.StringType] binding 'asdfasdf' to parameter: 3
[DEBUG,net.sf.hibernate.type.StringType] binding 'AL' to parameter: 4
[DEBUG,net.sf.hibernate.type.StringType] binding 'asdf' to parameter: 5
[DEBUG,net.sf.hibernate.type.StringType] binding 'physical' to parameter: 6
[DEBUG,net.sf.hibernate.type.StringType] binding 'ARM' to parameter: 7
[DEBUG,net.sf.hibernate.type.StringType] binding '402801e6fb17be2200fb17bf2d2d0005' to parameter: 8
[DEBUG,net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.impl.BatcherImpl] closing statement
[DEBUG,net.sf.hibernate.persister.EntityPersister] Updating entity: [com.hic.eboss.Business#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.SQL] update BUSINESS set name=?, type=?, description=?, state=?, person_id=? where id=?
Hibernate: update BUSINESS set name=?, type=?, description=?, state=?, person_id=? where id=?
[DEBUG,net.sf.hibernate.impl.BatcherImpl] preparing statement
[DEBUG,net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.hic.eboss.Business#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.type.StringType] binding 'sadfadf' to parameter: 1
[DEBUG,net.sf.hibernate.type.PersistentEnumType] binding '0' to parameter: 2
[DEBUG,net.sf.hibernate.type.StringType] binding 'asdfsad' to parameter: 3
[DEBUG,net.sf.hibernate.type.PersistentEnumType] binding '0' to parameter: 4
[DEBUG,net.sf.hibernate.type.StringType] binding '402801e6fb17be2200fb17bf2d2c0003' to parameter: 5
[DEBUG,net.sf.hibernate.type.StringType] binding '402801e6fb177bcc00fb177e141d0001' to parameter: 6
[DEBUG,net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,net.sf.hibernate.impl.BatcherImpl] closing statement
[DEBUG,net.sf.hibernate.collection.BasicCollectionPersister] Inserting collection: [com.hic.core.Person.phoneNumbers#402801e6fb17be2200fb17bf2d2c0003]
[DEBUG,net.sf.hibernate.collection.BasicCollectionPersister] collection was empty
[DEBUG,net.sf.hibernate.collection.BasicCollectionPersister] Inserting collection: [com.hic.core.Person.addresses#402801e6fb17be2200fb17bf2d2c0003]
[DEBUG,net.sf.hibernate.collection.BasicCollectionPersister] collection was empty
[DEBUG,net.sf.hibernate.impl.SessionImpl] post flush
[DEBUG,net.sf.hibernate.transaction.JDBCTransaction] commit
[DEBUG,net.sf.hibernate.impl.SessionImpl] flushing session
[DEBUG,net.sf.hibernate.engine.Cascades] processing cascades for: com.hic.eboss.Business
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to collection: com.hic.eboss.Business.addresses
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to collection: com.hic.eboss.Business.phoneNumbers
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to saveOrUpdate()
[DEBUG,net.sf.hibernate.impl.SessionImpl] saveOrUpdate() persistent instance
[DEBUG,net.sf.hibernate.engine.Cascades] done processing cascades for: com.hic.eboss.Business
[DEBUG,net.sf.hibernate.engine.Cascades] processing cascades for: com.hic.core.Person
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to collection: com.hic.core.Person.phoneNumbers
[DEBUG,net.sf.hibernate.engine.Cascades] cascading to collection: com.hic.core.Person.addresses
[DEBUG,net.sf.hibernate.engine.Cascades] done processing cascades for: com.hic.core.Person
[DEBUG,net.sf.hibernate.impl.SessionImpl] Flushing entities and processing referenced collections
[DEBUG,net.sf.hibernate.impl.SessionImpl] Collection found: [com.hic.eboss.Business.activities#402801e6fb177bcc00fb177e141d0001], was: [com.hic.eboss.Business.activities#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.SessionImpl] Collection found: [com.hic.eboss.Business.addresses#402801e6fb177bcc00fb177e141d0001], was: [com.hic.eboss.Business.addresses#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.SessionImpl] Collection found: [com.hic.eboss.Business.phoneNumbers#402801e6fb177bcc00fb177e141d0001], was: [com.hic.eboss.Business.phoneNumbers#402801e6fb177bcc00fb177e141d0001]
[DEBUG,net.sf.hibernate.impl.WrapVisitor] Wrapped collection in role: com.hic.core.Person.phoneNumbers
[DEBUG,net.sf.hibernate.impl.WrapVisitor] Wrapped collection in role: com.hic.core.Person.addresses
[DEBUG,net.sf.hibernate.impl.SessionImpl] Collection found: [com.hic.core.Person.phoneNumbers#402801e6fb17be2200fb17bf2d2c0003], was: [<unreferenced>]
[DEBUG,net.sf.hibernate.impl.SessionImpl] Collection found: [com.hic.core.Person.addresses#402801e6fb17be2200fb17bf2d2c0003], was: [<unreferenced>]
[DEBUG,net.sf.hibernate.impl.SessionImpl] Processing unreferenced collections
[DEBUG,net.sf.hibernate.impl.SessionImpl] Collection dereferenced: [com.hic.core.Person.phoneNumbers#402801e6fb17be2200fb17bf2d2c0003]
[DEBUG,net.sf.hibernate.transaction.JDBCTransaction] rollback
[DEBUG,net.sf.hibernate.impl.SessionImpl] transaction completion
[DEBUG,net.sf.hibernate.impl.SessionImpl] closing session
[DEBUG,net.sf.hibernate.impl.SessionImpl] disconnecting session
[DEBUG,net.sf.hibernate.impl.SessionImpl] transaction completion
[DEBUG,net.sf.hibernate.impl.SessionImpl] running Session.finalize()


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 5:38 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
What I find odd is that during the cascade, Hibernate find all the child objects and performs the inserts. So the collections are somehow becoming dereferenced (unreferenced?) /after/ the cascading?

There is something major I'm not seeing. hmm...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 7:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
well, since you did not show the get/set pair, I will stick with my first assumption.


Top
 Profile  
 
 Post subject: Ah Ha!
PostPosted: Thu Mar 04, 2004 7:32 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:21 pm
Posts: 40
Location: Honolulu, HI
Thanks Gavin, I found the problem.

(some background) I assumed that if Hibernate was building an object from scratch, it would pass in a proxy/wrapper/impl of a Collection to any setFoo(Collection collection) call. I thought that the proxy impl would have special Hibernate functionality. I therefore, didn't want to replace that collection with another collection in the next call to setFoo(Collection collection). So to compensate, I was doing:

setFoo(Collection collection) {
if (this.collection == null) {
this.collection = collection;
} else {
this.collection.clear();
this.collection.addAll(collection);
}
}

As you can see, I was trying to compensate for a misunderstanding of mine.

I changed the code to:

setFoo(Collection collection) {
this.collection = collection;
}

And it's now working great. Looks like Hibernate is smarter than I am! :)

Not sure where I got the first misunderstanding, but glad it's gone.

Thanks again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.