-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Can somebody explain this?
PostPosted: Thu Jan 15, 2004 2:23 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
I have the following association

ObjectA ---Many-to-many---ObjectB (unidirectional A to B)
ObjectC is a subclass of ObjectB

I use lazy initialization, and the same classes as proxies.

I add a set of objectCs to ObjectA and save the graph.

When I read this graph, I loop through the set of ObjectBs (which are in this case all ObjectCs), all of them are of type:

mypackage.ObjectB$$EnhancerByCGLIB$$d991a4fd

I believe this the proxy class. The problem is when I check real instances I get this unexpected result:

instanceof ObjectB returns true (expexted)

instanceof ObjectC returns false ???

Is this normal or am I missing someting?

When I use one-to-many assocaiation, getClass() returns mypackage.ObjectB (Without $$EnhancerByCGLIB$...), and everything works as expected.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 3:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is expected. It's explains at 12.1.
The expected class is of ClassB, so hibernate will proxy ClassB.
Proxying is done by extending ClassB. While being extended, it cannot be of ClassC (no multiple inheritance in Java).

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 3:44 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
Actually this makes sense. We load ObjectBs as proxies. ObjectB proxies are subclasses of ObjectB. They are unware of ObjectC.

But why do we have proxies for many-to-many and not for one-to-many?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 3:52 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
But why do we have proxies for many-to-many and not for one-to-many?

This also makes sense.

In one-to-many, Hibernate may be using find query: Looking for foreign keys in many side table.

In many-to-many, Hibernate is using find to find the many side primary keys in the association table, then using load query to get the many side objects (since it knows their primary keys).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.