0

I need to implements Threads for running some processes in my Java App with Spring and I'm using @Transactional to manage the Hibernate Transaction and commit the changes to the DB.

The issue is that when I use @Transactional in the threads, I get illegally attempted to associate a proxy with two open Sessions

I'm using @Transactional in the main thread (where I'm saving the objects in the database) and then call Future to execute the threads where I use @Transactional to recover and update the objects saved in the main thread, but I get the error mentioned above.

How is this suppose to work?

I tried to different flows and sending the IDs instead of the object to the threads, but in that way I get null from the database.

Faabass
  • 1,394
  • 8
  • 29
  • 58
  • See in https://stackoverflow.com/questions/10407301/how-to-use-spring-transaction-in-multithread. Duplicated!! – Aristofanio Garcia Aug 15 '18 at 21:44
  • Possible duplicate of [Hibernate: illegally attempted to associate a proxy with two open Sessions](https://stackoverflow.com/questions/14504591/hibernate-illegally-attempted-to-associate-a-proxy-with-two-open-sessions) – Roman-Stop RU aggression in UA Aug 15 '18 at 21:44
  • Well @AristofanioGarcia in that link they are using executors while I’m using Async methods. And there I’m not seeing that they have my problem. My problem is that although I have different threads, I want that the object in the main thread were visible for the child thread – Faabass Aug 15 '18 at 22:12
  • @RomanKonoval there they are manually opening and closing the hibernate session while I’m using Transactional and I don’t have too much control over that – Faabass Aug 15 '18 at 22:13
  • I don't see nothing about async in your question, but now is ok! Independ this you have the same problem. To help you, post an example, please! – Aristofanio Garcia Aug 16 '18 at 00:58

0 Answers0