Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Illegal attempt to associate a collection with two open sessions

 
nelson christos
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
These are the mapping files



 
nelson christos
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic