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.
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?
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.