-->
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.  [ 8 posts ] 
Author Message
 Post subject: CGLIB generated proxies don't inherit from proxied class
PostPosted: Fri Oct 22, 2004 10:41 am 
Beginner
Beginner

Joined: Tue Aug 17, 2004 5:06 am
Posts: 46
I have serious problems with the CGLIB generated proxy classes in a 1:1 relationship.

The generated proxies implement all the business interfaces of the proxied class, but they don't inherit from it, i.e.

IPerson myPersonProxy = bean.getPerson();
System.out.println(myPersonProxy instanceof IPerson); // -> true
System.out.println(myPersonProxy instanceof Person); // -> false

The Hibernate book says that the CGLIB generated proxies both...
* implement all interfaces that the proxied class implements
* inherits from the proxied class (or it's parent ?)

Any hints ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 11:01 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Be aware that proxied classes have problems with inheritance. If Person inherit from User and you have an association with a User, hibernate will create a User subclass and then cannot switch to a Person subclass


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 11:14 am 
Beginner
Beginner

Joined: Tue Aug 17, 2004 5:06 am
Posts: 46
This is exactly the case. All my beans that are persisted by Hibernate are inherited from a common baseclass.

If it's true what you say then those CGLIB proxies are rather useless, IMHO.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 11:25 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
No, the problems occurs only when you have an association to your base class.

If your assocation is to a Person instance then there is no problem. But if you association is to a IPerson instance then I think the proxy won't extends the Person class


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 24, 2004 2:00 pm 
Beginner
Beginner

Joined: Tue Aug 17, 2004 5:06 am
Posts: 46
scesbron wrote:
No, the problems occurs only when you have an association to your base class.

If your assocation is to a Person instance then there is no problem. But if you association is to a IPerson instance then I think the proxy won't extends the Person class


Ok, now I get it.

Unfortunately I must implement the business interfaces which constrain the types of the associated objects to other business interfaces, not to business objects.

Is there any way to tell CGLIB to generate proxies that derive from a user provided class instead of only implementing a business interface ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 3:14 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Quote:
Is there any way to tell CGLIB to generate proxies that derive from a user provided class instead of only implementing a business interface ?

You need to tell it for hibernate using mappings, just use implementation name in mappings to extend class, if this class implements interfaces then generated class will implement them too.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 4:31 am 
Beginner
Beginner

Joined: Tue Aug 17, 2004 5:06 am
Posts: 46
I already use the implementation class name in the mapping, i.e.

This is my mapping:
Code:
        <many-to-one
            name="businessReportInfo"
            class="com.whatever.model.hibernate.BusinessReportInfoHPB"
            cascade="all"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
            foreign-key="fk_BRI_C_business_report_info"
            column="fk_business_report_info"
        />


These are the setters:
Code:
   public com.whatever.model.BusinessReportInfoDOI getBusinessReportInfo() { return this.businessReportInfo; }
   public void setBusinessReportInfo(com.whatever.model.BusinessReportInfoDOI aBusinessReportInfo) { this.businessReportInfo = aBusinessReportInfo; }


However I still get proxies that just implement the IBusinessReportInfo, but that don't inherit from the object BusinessReportInfoHPB.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 4:54 am 
Beginner
Beginner

Joined: Tue Aug 17, 2004 5:06 am
Posts: 46
My fault: The proxy class in the class section was still pointing to IBusinessRelationshipInfo.

Wrong:
Code:
    <class
        name="com.whatever.model.hibernate.BusinessRelationshipInfoHPB"
        table="business_relationship_info"
        proxy="com.whatever.model.IBusinessRelationshipInfo"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
        discriminator-value="BUSINREL"
    >


Correct:
Code:
    <class
        name="com.whatever.model.hibernate.BusinessRelationshipInfoHPB"
        table="business_relationship_info"
        proxy="com.whatever.model.hibernate.BusinessRelationshipInfoHPB"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
        discriminator-value="BUSINREL"
    >


A thousand thanks to the forum members for pointing me into the right direction. You saved my day.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.