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.  [ 2 posts ] 
Author Message
 Post subject: StatefulPersistenceContext.containsCollection
PostPosted: Mon Apr 07, 2008 1:09 pm 
Newbie

Joined: Mon Jul 23, 2007 11:58 am
Posts: 15
Location: New Jersey
Can anyone give me a brief description of the purpose of StatefulPersistenceContext.containsCollection?? I am having troubles with a many to many set...I have an account that can contain many accounts who are considered friends. I created a link table that has the following attribu tes...

AccountFriend(id,AccountId, FriendId)
The accountId is the account with friends, and the friend id are all accounts associated to the base.

However, everytime i try to programmatically associate the accounts with friend accounts, I get a LazyInitializationException - no session or session was closed exception. I am using the Spring OpenSessionInViewFilter, and I only have one session factory pumping out sessions...I started taking a look at the hibernate code that leads to this exception, and the only thing that worries me is the call to StatefulPersistenceContext.containsCollection. I am almost 100% certain that a session exists and is opened when this exception is thrown...so that leaves the contains collection check...

My Account class has a set of associated Accounts as such.

Code:
public class Account {
  private Set<Account> friends;

}


My mapping is as follows...

Code:
<class name="com.asc.ltp.domain.Account" table="Account">
       <id name="id" column="Id">
           <generator class="org.hibernate.id.IncrementGenerator"/>
       </id>
  <set name="friends" table="AccountFriend" inverse="true">
          <key column="AccountId"/>
          <many-to-many class="com.asc.ltp.domain.Account" column="FriendId" />
      </set>
   
   </class>


My code to associate accounts is as follows...
Code:
public Account addFriendForAccount(Account base, Account accountToAdd) throws CheckedException {
       Account returnAccount = null;

       base.getFriends().add(accountToAdd);

       accountToAdd.getFriends().add(base);

       returnAccount = (Account) dao.updateDomain(base);


       return returnAccount;
   }


Does anyone have an idea on what could be going on here?


Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.x
Mapping documents:

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:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 10:01 am 
Newbie

Joined: Mon Jul 23, 2007 11:58 am
Posts: 15
Location: New Jersey
I figured this one out...

It was more an issue with my design...I was trying to lazy load a collection that was initialized in a different session. Just a product of hibernate learning growing pains...


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