• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Illegal attempt to associate a collection with two open sessions

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
nelson christos
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These are the mapping files



 
nelson christos
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic