-->
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.  [ 1 post ] 
Author Message
 Post subject: Proxy derived from wrong subclass
PostPosted: Mon Jan 08, 2007 4:00 pm 
Newbie

Joined: Fri Dec 29, 2006 10:43 am
Posts: 2
I have an application which has quite a large number of classes/tables (hence its difficult to attach
all the hbm.xml files and source). The app worked fine in 2.x and I'm now trying to migrate to 3.x of hibernate.

The problem I am getting is on a particular table/class that has about 15 subclasses (nested about 3 deep in
certain places). All of the tables have interfaces and matching implementation classes and the hbm files use the
relevant class=Implementation and proxy=Interface.

The method that is currently giving me problems is called 'getName'. This is not implemented by the base class
but is implemented by some of the subclasses. In some cases the method returns a column from the database and
in other cases it calculates the return value in a more complex manner.

However, I keep getting ClassCastExceptions (yes - I'm using LazyLoading) when I call the getName method on an
instance that I know provides it. But the proxy (because its derived from the wrong interface) does not.

If I debug the application then it would appear that the proxy class has resolved the destination of the
association to the correct class but the proxy itself is derived from the wrong interface. Each time I close Tomcat and
start again then I get the same problem but the proxy may be derived from a completely different interface - it
seems to be random.
Sometimes everything works ok but only if, by chance (?), it has chosen to derive the proxy from the correct
interface.


A rough approximation of my layout is:

class ContactSO{
}

class UserSO extends ContactSO{
String getName();
OfficeSO getOffice(); // set to lazy load the OfficeSO
String loginName;
String password;
}

class OfficeSO extends ContactSO{
String getName();
}

class OtherSO extends ContactSO{
// lots of these classes and some may or may not have a 'String getName()' method
}

So on login I use a Query to find the UserSO based on the login name and password. So far so good.
But when I try:
UserSO user = findLogin(loginName, password); // ok
user.getOffice().getName();

Then thats when I get the ClassCastException. Looking at the proxy it may be of type:
OtherSO$$$CGLibEnhancer$$$xxxxx
even though it has been resolved and it knows that the target is an 'OfficeSO'.

It doesn't call OfficeSO.getName but it looks as though it tries to cast the target to OfficeSO
and generates its own ClassCastException.


I'm tempted to think that it may be due to the fact that 'getName' is declared in the subclasses and maybe
I should rename them to make them unique. But I'm very loathe to do this since it will effect a lot of code and JSPs
and doesn't seem sensible unless someone has definitely shown this to be the cause of the problem.

Any ideas greatly appreciated!!


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

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.