Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Spring/Hibernate : JUnitTest : one-to-many dependency = LazyInitializationException

 
Chris Jackal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I load a Person.class which have an one-to-many dependency to an Address.class. When I call person.getAddresses I get an org.hibernate.LazyInitializationException.

I have found a solution for my junit test and add the following code in the
setUp() and tearDown() method :



It works fine.
After that I have read the javadoc of the class TransactionSynchronizationManager and find the followig text passage :
"To be used by resource management code but not by typical application code.
" The documentation of spring says smth. similiar.

Now my question : Is there a better way to get the same behavior in my
junittest than using TransactionSynchronizationManager ?

thx
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!