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