I have an object A and B where A has a reference of B and from B to A. B is configured as lazy in A.hbm.xml
When I do a session.createCriteria by giving the A's row-identifier it returns me the A object. And when I perform A.getB(), it returns me the object of type something like this B__$$_javassist_46.
What is this? Sometimes I have also seen when I invoke A.getB() it returns me the object of type B. Why sometimes it returns me B__$$_javaassist_46?
What is this?
What I have to do such that, my code for A.getB() should always return the object of type B and not as B__$$_javaassist_46 type?
Thanks,
Hari
This message was edited 1 time. Last update was at by hari haran sethu raman
Yes, those are called Proxies. the Proxy objects are created on the fly to be a "holder" object for the real object. Most of the time you get Proxies when you query A to B relationship where B is lazyloaded. So the real B data isn't gotten from the database until you try to access the B objects via the Proxies.
session.open // open a sssion and load object A
A.getB() //will return me B proxy . Here I should be careful to perform getImplementation for B actual object? But still I didnt do
A.getB().getRef() // will load B actual object since I did an action in B object through getRef
B b = A.getB() // no more proxy here
Yup, I think your'e getting it. So long as all of that is done within an open session, Hibernate will load the associated object. The associated object is no longer lazy, and you will no longer get any exceptions with regards to lazy loading.
By default, one to many and many to many relationships are lazy-loaded. You can override the default to eager. Conversely, one to one relationships are eagerly loaded by default.