Two words: side effects.
Code like this:
Code:
if( log.isDebugEnabled() ){
log.debug("size of collection: " + parent.getChildren().size());
}
Or objects that looks like this, that are subsequently used in a debug statement:
Code:
public class SideEffectObject{
...
public void toString(){
this.internalState = "something";
return super.toString()+internalState;
}
behave differently when debug is on/off.
Whenever somebody says "it's broken/works only when debug is on/off", in Java, it's
always wither a side effect like one of the above or a race condition. And it's
usually a side effect related issue.
Hibernate is subtle, especially when you have proxies and lazy collections flying around.
The issue is probably a side effect and is probably in your code rather than in the Hibernate code. Isolate the issue and then trace it in a debugger.