• 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic