Hi, we got a problem with the Query.setEntity() method. If the provided entity is a lazy loaded object (just to provide primary ID) and the logging level is DEBUG the exception (see below) is thrown. It's because of debugging informations in Loader.bindNamedParameters() on the line 1742 (link below) causing calling toString() method on the cglib-enhanced entity.
The behaviour has changed between Hibernate2 and Hibernate3. Is that behaviour or bug?
Thanks for the answer in advance.
Problematic line in the code:
http://www.koders.com/java/fid90774BD6E21147E8BFE82B633D4454578C0A1C34.aspx?s=org.hibernate.loader+Loader#L1742
Exception thrown:
Code:
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
at our.Entity$$EnhancerByCGLIB$$7cf9b60e.toString(<generated>)
at java.lang.String.valueOf(String.java:2615)
at java.lang.StringBuffer.append(StringBuffer.java:220)
at org.hibernate.loader.Loader.bindNamedParameters(Loader.java:1747)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1679)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:912)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at sun.reflect.GeneratedMethodAccessor154.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)