aspose file tools*
The moose likes Object Relational Mapping and the fly likes Illegal attempt to associate a collection with two open sessions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Illegal attempt to associate a collection with two open sessions" Watch "Illegal attempt to associate a collection with two open sessions" New topic
Author

Illegal attempt to associate a collection with two open sessions

nelson christos
Ranch Hand

Joined: Aug 08, 2006
Posts: 57
Hi,

I have a Voyage.hbm like this

<hibernate-mapping package="com.jmbaxi.model.agencyops">
<class name="com.jmbaxi.model.agencyops.Voyage" table="DAILY_VSL_DATA" lazy="false">
<id name="lineupNo" column="LINEUP_NO">
<generator class="assigned"></generator>
</id>
..........

<join table="AOPS_VSLVOY_AUX_DTLS" optional="true">
<key column="LINEUP_NO"></key>
..........
</join>
</class>
</hibernate-mapping>

So when i am saving a voyage everything goes well
however when i added a
<set name="dailyCargo" inverse="true" order-by="REP_NO">
<key column="LINEUP_NO"></key>
<one-to-many class="DailyCargo"/>
</set>
it started giving me this exception

org.springframework.orm.hibernate3.HibernateSystemException: Illegal attempt to associate a collection with two open sessions; nested exception is org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions

i am using Spring OSIV filter.

Thanks


i think therefore i am
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Can you post your code and also mappings of the related class too, and also use the CODE button below to put your mappings and code in between those two tags so that your formatting of indentations remain, without indentation the stuff is very hard to read.

In your code, do you have two Sessions open? If so, close the first one before starting the second.

In your related class mapping, I am assuming you have the inverse Many-To-One, correct?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
nelson christos
Ranch Hand

Joined: Aug 08, 2006
Posts: 57
These are the mapping files



nelson christos
Ranch Hand

Joined: Aug 08, 2006
Posts: 57
The controller function for saving the voyage



The service function is



and lastly the dao layer



I dont see any new session getting opened in here. Is this something to
do with transactions
Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

I haven't read the code yet, but I saw this at the end of your post

"Is this something to do with transactions"

The relationship between Session and Transactions is one to one. You cannot start and commit a transaction, then try to create another one within the same Session session (meaning open and close).

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

OK, so then is Spring creating the Session and Transactions for you. I am sorry but I have not used Spring, so I am not familiar with how the Spring/Hibernate combination works.

Mark
nelson christos
Ranch Hand

Joined: Aug 08, 2006
Posts: 57
Thanks for your reply Mark

The problem was with the OSIV filter mapping.
I had given singleSession as false
so it was creating a session on get* and another on save*. I changed it to
true and alls well
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Originally posted by nelson christos:
Thanks for your reply Mark

The problem was with the OSIV filter mapping.
I had given singleSession as false
so it was creating a session on get* and another on save*. I changed it to
true and alls well


Well, good job.

Mark
 
jQuery in Action, 2nd edition
 
subject: Illegal attempt to associate a collection with two open sessions