File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes HQL join fetch and $EnhancerByCGLIB$ issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "HQL join fetch and $EnhancerByCGLIB$ issue" Watch "HQL join fetch and $EnhancerByCGLIB$ issue" New topic
Author

HQL join fetch and $EnhancerByCGLIB$ issue

Eugene Babiev
Greenhorn

Joined: Jan 26, 2006
Posts: 19
if to specify explicitly the <class name="ClassName"... lazy="false">
then after executing HQL query the retrieved objects are not proxied by CGLIB

but if the <class name="ClassName" ... lazy="true"> then after the hql with 'fetch join' execution i get the instance of ClassName$EnhancerByCGLIB$121212

is this the bug? how can i get rid of $EnhancerByCGLIB$ and get the desired ClassName?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

"Eugene"

Please can you update your display name so it matches our Naming Policy. It should contains a first and last name. You can do this here. Thanks!


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


is this the bug? how can i get rid of $EnhancerByCGLIB$ and get the desired ClassName?

No its not a bug, and the value you see is the class name. CGLib is a code generation library used to create proxy classes on the fly. The proxy will contain a unpopulated instance of the persistant class it is proxying - explore the object in a debugger and you will find it.
Eugene Babiev
Greenhorn

Joined: Jan 26, 2006
Posts: 19
the problem was that 'join fetch' shouldn't use proxy, but id does. Of course it returns initialized proxy but the className is not the original name.

More over if you use debugger in Eclipse it doesn't correstly shows its properties, they are null, although in reality the are not.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


the problem was that 'join fetch' shouldn't use proxy, but id does.

Hmm. You are right in your assertion that a fetch join will initialize the associated objects using one query (regardless of any association mapping attributes). Is this happening? Whether or not this returns instances of the assoicated persistant class, or its initialized proxy I can't remember. what happens if you don't define a proxy class?


More over if you use debugger in Eclipse it doesn't correstly shows its properties

The properties of the proxy will appear null. The proxy is just a route to the actual persistant class, it doesn't hold the values of the class itself. Explore the properties of the proxy and you will find the persistant object with its properties populated.

But perhaps we are discussing the wrong issue: why do you need to get the class name?
Eugene Babiev
Greenhorn

Joined: Jan 26, 2006
Posts: 19
the problem with the CGLIB arises when you use the retrieved proxied object in reflection API operations (for instance, while building JDOM element)

Whether or not this returns instances of the assoicated persistant class, or its initialized proxy I can't remember

but this is the main buggish point i think because if it returns initialized proxy then that means you cant emulate the lazy="false" at runtime.
[ May 16, 2006: Message edited by: Eugene Mr ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


but this is the main buggish point i think because if it returns initialized proxy then that means you cant emulate the lazy="false" at runtime.

Well you'll have to double-check whether I'm right about an initialized proxy. Like I say, I don't know off the top of my head. However whether it returns a proxy or an instance of the actual persisted class doesn't mean you can't change fetching strategies at runtime. Lazy initialization and eager fetching relate to how Hibernate gets the data from the DB (one bit of SQL or lots of seperate SQL statements) not how it returns the data. Enable SQL logging and see if it is behaving this way.
Eugene Babiev
Greenhorn

Joined: Jan 26, 2006
Posts: 19
the answer to the problem is the follows:

in this case the question is how to safely extract the original object out of CGLIB wrapper?

and the answer is:
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Glad you found an answer, and thanks for taking the time to post it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HQL join fetch and $EnhancerByCGLIB$ issue