IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of JBoss AS 5 Development this week in the JBoss forum
or Spring Dynamic Modules in Action in the Spring forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Object Relational Mapping
 
RSS feed
 
New topic
Author

Hibernate - sometimes returns the object of type java assist

hari haran sethu raman
Greenhorn

Joined: Nov 10, 2008
Messages: 11

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

This message was edited 1 time. Last update was at by hari haran sethu raman

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Messages: 14714

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

Spock's Beard - Foabia app - Money Mgt Calculator - Paper Clips
How to Ask Questions the Smart Way FAQ
hari haran sethu raman
Greenhorn

Joined: Nov 10, 2008
Messages: 11

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
Bartender

Joined: Aug 26, 2006
Messages: 4517

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

Author of Hibernate Made Easy, What is WebSphere???, Portlet Programming Made Easy and the SCJA Certification Guides
My Hibernate and JPA Tutorials * My Mock Java Certification Exams * My Online Java Tutorials * My CBT Portlet Tutorials.

 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Object Relational Mapping
 
RSS feed
 
New topic
replay challenge