-->
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.  [ 5 posts ] 
Author Message
 Post subject: "collection w/ two sess" exc but using 1 sess and
PostPosted: Wed Jan 24, 2007 8:19 pm 
Newbie

Joined: Wed Jan 17, 2007 9:48 pm
Posts: 9
Ok this one is starting to hurt my head so I'm hoping that there is someone who'll be able to provide some insight.

Using ThreadLocalSessionContext and JDBCTransactionFactory via Spring's @Transactional annotation.
From the logs the transactional element looks to be working fine e.g

Code:
2007-01-25 10:57:37,021 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Found thread-bound Session [org.hibernate.impl.SessionImpl@e0a659] for Hibernate transaction
2007-01-25 10:57:37,021 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Using transaction object [org.springframework.orm.hibernate3.HibernateTransactionManager$HibernateTransactionObject@150b2d]
2007-01-25 10:57:37,021 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Participating in existing transaction


however when trying to persist using an object returned Hibernate with following transaction output
Code:
2007-01-25 10:57:44,105 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Found thread-bound Session [org.hibernate.impl.SessionImpl@e0a659] for Hibernate transaction
2007-01-25 10:57:44,105 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Using transaction object [org.springframework.orm.hibernate3.HibernateTransactionManager$HibernateTransactionObject@384d99]
2007-01-25 10:57:44,105 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Participating in existing transaction

yields
Code:
2007-01-25 10:57:44,105 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Found thread-bound Session [org.hibernate.impl.SessionImpl@e0a659] for Hibernate transaction
2007-01-25 10:57:44,105 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Using transaction object [org.springframework.orm.hibernate3.HibernateTransactionManager$HibernateTransactionObject@384d99]
2007-01-25 10:57:44,105 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Participating in existing transaction
2007-01-25 10:57:44,144 [main] ERROR au.com.copyright.tns.dao.hibernate.core.DpcMetadataDaoImpl  - Hibernate Exception: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
2007-01-25 10:57:44,144 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Triggering beforeCompletion synchronization
2007-01-25 10:57:44,144 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Initiating transaction rollback
2007-01-25 10:57:44,145 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Rolling back Hibernate transaction on Session [org.hibernate.impl.SessionImpl@e0a659]
2007-01-25 10:57:44,175 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Triggering afterCompletion synchronization
2007-01-25 10:57:44,175 [main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager  - Closing Hibernate Session [org.hibernate.impl.SessionImpl@e0a659] after transaction


Any ideas why / how?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 12:05 am 
Newbie

Joined: Wed Jan 17, 2007 9:48 pm
Posts: 9
there is a relationship like one-to-many relationship of Person to Name involved. The first query gets a list of all names and saves the string representation to a hash along with the ID from the associated person object (used for Lucene corpus) then later for every name that matches the Person object is retrieved based on the stored ID and is added to 3rd object.

This all happens within what I believe is 1 session and 1 transaction however it is upon persisting the 3rd object that the
Code:
org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
occurs. If the ID of Person is replaced by a fixed value then all persists ok. So, it is the initial storing of the ID of the Person object through the Name object that is conflicting with the Person object being saved.

Anyone got any ideas?

Could it be that the relationship is being instantiated from 2 directions i.e via Name -> Person and then directly to Person?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 3:20 am 
Newbie

Joined: Mon Feb 20, 2006 6:31 am
Posts: 17
I'm not an expert on this, but maybe this is a clue. The last time I had this exception, it was because somewhere in my code a session hadn't been closed. At that time I was working on legacy code where possible exceptions weren't caught and the statement session.close() was skipped. Maybe you could check that you're always closing your session?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 3:20 am 
Newbie

Joined: Mon Feb 20, 2006 6:31 am
Posts: 17
I'm not an expert on this, but maybe this is a clue. The last time I had this exception, it was because somewhere in my code a session hadn't been closed. At that time I was working on legacy code where possible exceptions weren't caught and the statement session.close() was skipped. Maybe you could check that you're always closing your session?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 30, 2007 12:41 am 
Newbie

Joined: Wed Jan 17, 2007 9:48 pm
Posts: 9
PEBKAC

Ok the problem was me. I have a GenericDao with methods for persisting and deleting as they operate on Objects. Other DAOs then extend GenericDao. I was running a single transaction for the process, all DAOs using read-only and SUPPORTS except GenericDao which used REQUIRED and was being read-write. Given the above I struggled to see where I'd gone wrong but it turned out that while GenericDao was using getCurrentSession() the other DAOs were using openSession().


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