-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Proxy TypeCast Problem with inheritance
PostPosted: Fri Nov 23, 2007 6:02 am 
Newbie

Joined: Mon Aug 21, 2006 12:44 pm
Posts: 12
Hello,

we have a problem with inheritance and TypeCast.
Let me show you the situation first:


Code:
@Entity
public class AClassImpl implements AClass{

   @ManyToOne(fetch=FetchType.LAZY, targetEntity=BClassImpl.class)
   private BClass bClass;

/* getter setter here*/
}



Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class BClassImpl implements BClass{
   
    @OneToMany(targetEntity = AClassImpl.class, mappedBy = "bClass")
    private List<AClass> aClasses;

/* getter setter here*/
}



Code:
@Entity
public class CClassImpl implements CClass extends BClass{
   
}



The Interfaces have the same inheritance than the actual classes have.
CCLass extends BClass


I am in the situation, that AClass can have either BClass or CClass. It works without a problem.

EXCEPT the one most important thing! If AClass references a instance of CClass and if I do a session.get on AClass and later try to access the property bClass (which is actaully a cClass now) I get a TypeCastException when I try to do this:
Code:
(CClass) myAClass.getBClass();


Because bClass is a Hibernate Proxy instead of the real BClass type. (Which I coulld cast to CClass without a prolbem.)

The sollution to this is to change the FetchType.LAZY to FetchType.EAGER. But I don't want the eager fetching in this situaion. Is there a sollution for this problem?

any help is greatly apreciated.
Santo.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 23, 2007 7:15 am 
Beginner
Beginner

Joined: Thu Nov 02, 2006 9:38 am
Posts: 32
Location: Belgium
http://www.hibernate.org/hib_docs/refer ... ng-proxies

This gives more information about your problem. I'm facing very similar problems now, and I'm still not sure what the general solution is.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 18, 2007 9:08 am 
Beginner
Beginner

Joined: Mon Sep 12, 2005 3:27 am
Posts: 48
Hello,

i also have implemented a Lazy 1:1 relation with Inheritance now. I understand the problem, that the created proxies are not directly castable to the implementation-classes. But i'm facing now another badly problem. My inherited class-proxies are implementing the wrong interfaces!!

For Testcase see JIRA-3019 or Hibernate-Forum. Can you prove, that this problem also exists for you ?


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