Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

EJB3 inheritance strange behavior

Thread view: 
sveta - 27 Mar 2007 09:24 GMT
Hi all,

sorry for my not perfect English ...

I have table per subclass situation in my database. So i use
@Inheritance(strategy=InheritanceType.JOINED) to map my entities. When
i try to get the instance of subclass, everithing is OK. In my sql log
i see the query that joins two tables (mapped to superclass and mapped
to subclass that i want to get) and returns the correct result.
BUT, when i want to get the instance of superclass, i see the query
that joins table mapped to superclass and ALL tables mapped as
subclasses, though return only infomation from one header table.

Is such behavior correct? And if I have 20 subclasses (and subtables)?
can i change this behavior somehow?

i have the following structure of entities:

@Entity
@Table(name="X.Ref")
@Inheritance(strategy=InheritanceType.JOINED)
public class Ref implements Serializable{

    private Integer id;
    @Id  @GeneratedValue
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }

    private String name = "";
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    private String status = "r";
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
}

@Entity
@Table(name="X.OrgAdd")
@PrimaryKeyJoinColumn(name="Pnt")
public class Organization extends Ref {
    private String address = "";
               private String full_name="";
               ...
}

@Entity
@Table(name="X.PeopleAdd")
@PrimaryKeyJoinColumn(name="Pnt")
public class Person extends Ref {
    private String sex = "";
               private String addressfact="";
               private String email="";
               ...
}

@Entity
@Table(name="X.ClientAdd")
@PrimaryKeyJoinColumn(name="Pnt")
public class Client extends Ref {
    private String client_code = "";
               private String depo_code="";
               ...
}

and several other subclasses.
I use JBOSS 4.0.5.

thanks in advance.
sveta - 27 Mar 2007 09:34 GMT
upd:

i make such queries:

Ref r=(Ref)em.createQuery("from Ref r where
r.id="+id).getSingleResult();
in sql log i see smth like "select * from X.Ref r left outer join
X.PeopleAdd p on ...  X.OrgAdd o left outer join X.ClientAdd c on ..."

and

Person p = (Person)em.createQuery("from Person p where
p.id="+id).getSingleResult();
in log i see "select * from X.Ref left outer join X.PeopleAdd on ..."
JB - 27 Mar 2007 11:31 GMT
> Is such behavior correct?

I don't know the O/R-Mapper you use, but: yes, this behavior is what I
would expect.
Furthermore, the O/R-Mapper should return an instance of the subclass,
if the join was successful with either sub table.

Regards
Jens
sveta - 27 Mar 2007 12:08 GMT
> > Is such behavior correct?
>
[quoted text clipped - 5 lines]
> Regards
> Jens

i use EJB 3.0 embedded into JBOSS 4.0.5.

thanks for your opinion,
but to me, other behavior seems natural.
If i had simple Java classes (not mapped to tables), then if i wanted
to get the instance of superclass, i would get exactly what i want and
i will spend same time, not depending what subclasses and how much of
them this class had.

And here i see, that i want to get only three fields of the table Ref
and JBOSS makes query to ALL dependent tables instead, and select ALL
fields of those tables. Though the result is right, the time is
wasting.

Perhaps i'm wrong in my OR-mapping strategy. in reality i need such
structure in which i could get quickly the instances of Ref, and
_sometimes_ much more complicated instances of subclasses (here the
requirements for time are not so strict). and all this complex
instances MUST extend Ref.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.