[jboss-user] [EJB 3.0] - Proxy-Class

MistaMoasn do-not-reply at jboss.com
Thu Nov 15 05:10:16 EST 2007


Hello!

I got a problem which is similar to the following posts (no solution yet provided):
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=88515
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=121044

I have entities which are organized in an inheritance hierarchy (please have a look a the code below). When i execute a query (please look at the stateful session bean below) it returns a proxy-object. But it should be an instance of the concrete entity bean. I am facing this problem only when querying in an inheritance hierarchy. For "normal" entity beans it works fine.

How can i tell the entity beans in the inheritance hierarchy that the whole hierarchy should be fetched eager without eager fetching.

I found a (not suitable) workaround when i use the annotation @Proxy(lazy =false) at base class level. With this annotation i get the concrete instance of the entity bean (RfAuthProject-instance with id 483 like in the example below) but all associations of each entity in the hierarchy are eager fetched too. That's a problem because, it gets really slow.

How can i achieve that only the inheritance hierarchy is fetched and none of the associations?

Thanks in advance for your help.

kind regards
Patrik

ps.: 
Environment: JDK1.5, JBoss 4.2.1 (with EJB3.0 embedded)

pps.: 
Example code below:


  | @Stateful
  | public class MainProjectDTO implements MainProjectLocal, MainProjectRemote
  | {
  |   public Project getProject()
  |   {
  |     // trivial example for my problem
  |     Query query1 = em.createQuery("FROM Project p WHERE p.id = 483");
  |     Project project = query1.getSingleResult();
  | 
  |    // the returned project is a proxy like Project_$$_javassist_16 but
  |    // should be an instance of RfAuthProject because it really is one.
  | 
  | 
  |     // here lies my problem
  |     // project with id=483 is definitly a RfAuthProject
  |     if (project instanceof Project) --> true
  |     if (project instanceof RfProject) --> false
  |     if (project instanceof RfAuthProject) --> false
  | 
  |    // following class cast fails
  |    RfAuthProject rfAuthProject = (RfAuthProject) project;
  | 
  | 
  |     return project;
  |   }
  | }
  | 

Three entity beans in an inheritance hierarchy.


  | @Entity
  | @Inheritance(strategy = InheritanceType.JOINED)
  | @Table(name = "project")
  | public class Project
  | {
  | }
  | 
  | @Entity
  | @Table(name = "rf_project")
  | @Inheritance(strategy = InheritanceType.JOINED)
  | @PrimaryKeyJoinColumn(name = "id")
  | public class RfProject extends Project
  | {
  | }
  | 
  | @Entity
  | @Table(name = "rf_auth_project")
  | @Inheritance(strategy = InheritanceType.JOINED)
  | @PrimaryKeyJoinColumn(name = "id")
  | public class RfAuthProject extends RfProject
  | {
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4104908#4104908

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4104908



More information about the jboss-user mailing list