• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HQL join fetch and $EnhancerByCGLIB$ issue

 
Eugene Babiev
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad you found an answer, and thanks for taking the time to post it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic