Zolf
asked on
Illegal attempt to associate a collection with two open sessions
Hello there,
I am trying to update a record in one of the frames in my application and I get this error. Before it was working fine. I mean I could add and update the records in the frame. then I added the delete operation and the del is working but when I try to update I get this error. please help. I have attached my classes.
cheers
Zolf
org.hibernate.HibernateExc eption: Illegal attempt to associate a collection with two open sessions
=== 2014-01-28 09:45:18,612 [l0-2] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
=== 2014-01-28 09:45:18,612 [l0-2] DEBUG RPCManager - DMI response, dropExtraFields: true
=== 2014-01-28 09:45:18,612 [l0-2] INFO Compression - /kaizenerpweb/sc/IDACall: 144 -> 132 bytes
at org.hibernate.collection.A bstractPer sistentCol lection.se tCurrentSe ssion(Abst ractPersis tentCollec tion.java: 432)
at org.hibernate.event.def.On UpdateVisi tor.proces sCollectio n(OnUpdate Visitor.ja va:66)
at org.hibernate.event.def.Ab stractVisi tor.proces sValue(Abs tractVisit or.java:12 4)
at org.hibernate.event.def.Ab stractVisi tor.proces sValue(Abs tractVisit or.java:84 )
at org.hibernate.event.def.Ab stractVisi tor.proces sEntityPro pertyValue s(Abstract Visitor.ja va:78)
at org.hibernate.event.def.Ab stractVisi tor.proces s(Abstract Visitor.ja va:146)
at org.hibernate.event.def.De faultSaveO rUpdateEve ntListener .performUp date(Defau ltSaveOrUp dateEventL istener.ja va:316)
at org.hibernate.event.def.De faultSaveO rUpdateEve ntListener .entityIsD etached(De faultSaveO rUpdateEve ntListener .java:246)
at org.hibernate.event.def.De faultSaveO rUpdateEve ntListener .performSa veOrUpdate (DefaultSa veOrUpdate EventListe ner.java:1 12)
at org.hibernate.event.def.De faultSaveO rUpdateEve ntListener .onSaveOrU pdate(Defa ultSaveOrU pdateEvent Listener.j ava:93)
at org.hibernate.impl.Session Impl.fireS aveOrUpdat e(SessionI mpl.java:5 35)
at org.hibernate.impl.Session Impl.saveO rUpdate(Se ssionImpl. java:527)
at org.hibernate.impl.Session Impl.saveO rUpdate(Se ssionImpl. java:523)
at com.kaizen.erp.server.buss inessLogic .supplier. SupplierOr derBussine ssLogic.sa veSupplier Order(Supp lierOrderB ussinessLo gic.java:1 34)
at com.kaizen.erp.server.buss inessLogic .supplier. SupplierOr derBussine ssLogic.ad d(Supplier OrderBussi nessLogic. java:110)
at sun.reflect.NativeMethodAc cessorImpl .invoke0(N ative Method)
at sun.reflect.NativeMethodAc cessorImpl .invoke(Un known Source)
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Unknown Source)
at java.lang.reflect.Method.i nvoke(Unkn own Source)
SupplierOrderBussinessLogic.java
SupplierOrder.hbm.xml
I am trying to update a record in one of the frames in my application and I get this error. Before it was working fine. I mean I could add and update the records in the frame. then I added the delete operation and the del is working but when I try to update I get this error. please help. I have attached my classes.
cheers
Zolf
org.hibernate.HibernateExc
=== 2014-01-28 09:45:18,612 [l0-2] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
=== 2014-01-28 09:45:18,612 [l0-2] DEBUG RPCManager - DMI response, dropExtraFields: true
=== 2014-01-28 09:45:18,612 [l0-2] INFO Compression - /kaizenerpweb/sc/IDACall: 144 -> 132 bytes
at org.hibernate.collection.A
at org.hibernate.event.def.On
at org.hibernate.event.def.Ab
at org.hibernate.event.def.Ab
at org.hibernate.event.def.Ab
at org.hibernate.event.def.Ab
at org.hibernate.event.def.De
at org.hibernate.event.def.De
at org.hibernate.event.def.De
at org.hibernate.event.def.De
at org.hibernate.impl.Session
at org.hibernate.impl.Session
at org.hibernate.impl.Session
at com.kaizen.erp.server.buss
at com.kaizen.erp.server.buss
at sun.reflect.NativeMethodAc
at sun.reflect.NativeMethodAc
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
SupplierOrderBussinessLogic.java
SupplierOrder.hbm.xml
Can you provide the code for your HibernateUtils class please?
ASKER
Ok, I believe this error is due to the "supplierOrder" object being retrieved in the "getSupplierOrderFromReque st" method (line 108) under one session and then attempting to saveOrUpdate the same object in the "saveSupplierOrder" method (line 110) under a new session. And since your session handling seems "a bit odd" and you are only closing sessions when "session.isConnected()" is false (and I'm guessing that generally it isn't false) that the first session is still open when you are trying to manipulate your object in the second session.
So some potential fixes are... properly closing the session regardless if it is still connected may work (although that may introduce other problems, it's hard to tell with your code a bit all over the place). Otherwise, try and only open the one session for the entire request, rather than having that "add" method where you call additional methods that each opens its own session.
So some potential fixes are... properly closing the session regardless if it is still connected may work (although that may introduce other problems, it's hard to tell with your code a bit all over the place). Otherwise, try and only open the one session for the entire request, rather than having that "add" method where you call additional methods that each opens its own session.
ASKER
thanks for your comments. but It was working properly before when I added the one to many in the SupplierOrder.hbm.xml to be able to perform delete cascade, then this issue came up in the update process.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
also when I try to run a simple code like this too I get the error. I guess it has to do with this one to many which I added to my hbm.xml file
public static void main(String []args){
SupplierOrder supplierOrder = getInstance().getSupplierO rderById(1 L);
if(supplierOrder!=null)
getInstance().saveSupplier Order(supp lierOrder) ;
else
System.out.println("null") ;
}
public static void main(String []args){
SupplierOrder supplierOrder = getInstance().getSupplierO
if(supplierOrder!=null)
getInstance().saveSupplier
else
System.out.println("null")
}