Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads and transactions : nested transactions not supported  RSS feed

 
L Ld
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I am trying to insert rows into 2 different and unrelated tables with 2 threads running concurrently.

The way I am doing it is not working, can you help me solve my issue ?

Here is my main code :



And here is my DAO :



And the error :


Many thanks
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your sharing the session reference variable in the two threads ?? It can be opened twice, begin transaction twice etc. Also you should have set session to null when you closed it (but that's still wrong ;-) , just a bit less wrong ie that would make it correct for single threading but still not multithreading).

Probably what you meant was session local to setA or setB, failing that you could synchronize the methods but one would run after the other, or thread local it or something else ;-)

 
L Ld
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thank you !

I put a session in each thread.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!