tags:

views:

32

answers:

1

Hi, I have to add a lazy=true to a property & i have add a ant task to intrument the class to enable hibernate to make it lazy in my pom.

is there a way to test that now this property is in lazy mode in runtime without watching the hibernate sql console output? I mean with unit testing (im using spring test with junit). I dont want to test that the lazy attribute is present in the xml mapping. This alone doesnt ensure taht hibernate will treat it as a lazy property.

I want a junit test in order to be sure that this bug revealed by a tester will not more appear in the future (i'm not alone in the project).

I'm following the (best?) practice that every not trivial bug should have an automatic test in order to prevent his coming back.(by the way, i've pick up the idea from Spring framework tests)

+1  A: 

You can load the entity, close the session, and then assert that a LazyInitializationException is thrown when you access the property.

Henning
Thanks a lot Henning !!!
mada
@mada: You're welcome! By the way, you can show your appreciation by upvoting and accepting answers.
Henning
@mada Work on your accept rate @Henning Up Henning (+1)
Arthur Ronald F D Garcia