-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: CGLIB exception
PostPosted: Wed Apr 27, 2005 11:16 am 
Newbie

Joined: Wed Apr 27, 2005 11:04 am
Posts: 2
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(&lt;generated&gt;)
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]

_________________
A polar bear is a rectangular bear after a coordinate change.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 3:12 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Run test in single session, open it in setUp() and close in tearDown(). You can use instance variable to store session for test if it runs in single thread.


Top
 Profile  
 
 Post subject: But what about...
PostPosted: Wed Apr 27, 2005 4:57 pm 
Newbie

Joined: Wed Apr 27, 2005 11:04 am
Posts: 2
...when I start construction of the web application, where I definitely will not be in single session mode? This is telling me that Object.equals() will not work on objects generated by Query or SQLQuery within Hibernate.

_________________
A polar bear is a rectangular bear after a coordinate change.


Top
 Profile  
 
 Post subject: Re: But what about...
PostPosted: Wed Apr 27, 2005 5:12 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
archimedes1967 wrote:
...when I start construction of the web application, where I definitely will not be in single session mode? This is telling me that Object.equals() will not work on objects generated by Query or SQLQuery within Hibernate.


Object.equals() will work as long as all of the properties being access in the equals() method have been loaded.

All of the properties that make up a true business equal() condition should be aggressively loaded.


Top
 Profile  
 
 Post subject: Re: But what about...
PostPosted: Thu Apr 28, 2005 8:36 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
archimedes1967 wrote:
...when I start construction of the web application, where I definitely will not be in single session mode? This is telling me that Object.equals() will not work on objects generated by Query or SQLQuery within Hibernate.

Yes, you will need to store session in threadlocal. I recomment not to store persistent data in httpsession or in servlet context, it will help to avoid many problems(store ID only and use global cache to optimize read operations).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.