-->
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: JPA problem with Lists and Inheritance types...
PostPosted: Thu Oct 23, 2008 5:15 am 
Newbie

Joined: Thu Oct 23, 2008 4:42 am
Posts: 4
Hibernate version: 3 - also using entity manager and annotations for JPA

I have an entity with 2 collections in it (both Lists). The collections are both parameterised to subclass types of the same abstract superclass:

Code:
@OneToMany(targetEntity=ClassTimetable.class)
@JoinTable (name="uwe_timetable_users",
      joinColumns=@JoinColumn(name="userID"),
      inverseJoinColumns=@JoinColumn(name="TtID")
)
private List<ClassTimetable> classTimetables;

@OneToMany(targetEntity=ExamTimetable.class)
@JoinTable (name="uwe_timetable_users",
      joinColumns=@JoinColumn(name="userID"),
      inverseJoinColumns=@JoinColumn(name="TtID")
)
private List<ExamTimetable> examTimetables;


The result of either getExamTimetables() or getClassTimetables() both return all the timetables regardless of type...

How can I get hibernate to distinguish which timetables to return? I'm using discriminator columns to distinguish types in the Db with a SINGLE_TABLE strategy. I have little/no control over the Db schema.

MS SQL Server 2005

The generated SQL (show_sql=true):

Code:
select
        classtimet0_.userID as userID1_,
        classtimet0_.TtID as TtID1_,
        classtimet1_.TtID as TtID1_0_,
        classtimet1_.disabledText as disabled3_1_0_,
        classtimet1_.PortalURL as PortalURL1_0_,
        classtimet1_.TtName as TtName1_0_
    from
        uwe_timetable_users classtimet0_
    left outer join
        UWE_TIMETABLES classtimet1_
            on classtimet0_.TtID=classtimet1_.TtID
    where
        classtimet0_.userID=?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2008 7:01 am 
Newbie

Joined: Thu Oct 23, 2008 4:42 am
Posts: 4
As an update - it appears that all rows are being returned as ClassTimetable even if the discriminator column specifies that it's an ExamTimetable...

The code for the various class is as follows:

Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TtType", discriminatorType=DiscriminatorType.STRING)
@Table(name="UWE_TIMETABLES")
public abstract class Timetable


Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("C")
@Table(name="UWE_TIMETABLES")
public class ClassTimetable extends Timetable


Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("E")
@Table(name="UWE_TIMETABLES")
public class ExamTimetable extends Timetable


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2008 9:29 am 
Newbie

Joined: Thu Oct 23, 2008 4:42 am
Posts: 4
I must be missing something to do with Collections because, if I try and get an entity object individually via a find method then the right type is always returned...

If I try and get them via a genericised list, however, it returns the wrong type...

In fact the query doesn't even use the @DiscriminatorValue at all...


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.