• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate - sometimes returns the object of type java assist

 
hari haran sethu raman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
hari haran sethu raman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok. In the following sequence, do you mean that,

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

Thanks,
Hari
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic