Scenario: I have a jUnit test driver that with a setUp(), tearDown(), and a test method.
setUp() constructs an object, inserts it into the database, and keeps a reference for later destruction.
tearDown() destroys the object in the database and releases the instance.
the test method then invokes a business method that will eventually lead to a Query.uniqueResult() being invoked. This works great. The issue is when, in the jUnit test method, an assertEquals() is done on the stored reference and the new reference. CGLIB doesn't appear to like that.
Hibernate version:
3.0.1
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Code:
try {
session = HibernateUtilities.getSession();
Query q = session.createQuery(USER_QUERY);
q.setString(0, userid);
rvalue = (User) q.uniqueResult();
}
catch (final HibernateException he) {
LOGGER.warn("Problem executing logon query.", he);
rvalue = null;
}
finally {
if (session != null) {
session.close();
}
}
Full stack trace of any exception that occurs:Code:
<error message="could not initialize proxy - the owning Session was closed"
type="org.hibernate.LazyInitializationException">
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
at (company pkg name).model.Contact$$EnhancerByCGLIB$$5d913e36.equals(<generated>)
at (company package name).model.User.equals(User.java:109)
at (company package name).model.TestUser.testLogon(TestUser.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
</error>
Name and version of the database you are using:MySQL 4.0.1
The generated SQL (show_sql=true):Debug level Hibernate log excerpt:[/code]