EJB3 inheritance strange behavior

S

sveta

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.
 
S

sveta

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 ..."
 
J

JB

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
 
S

sveta

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top