[jboss-user] [EJB 3.0] - Inconsistent behavior of Discriminator

hitman_in_wis do-not-reply at jboss.com
Thu Aug 10 18:27:56 EDT 2006


I have entity superclass MYSUPERCLASS
-------------------------------------------------------------------
@Entity
  | @Table(name="TABLE_A")
  | @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
  | @DiscriminatorColumn(name="MYDESCRIMCOLUMN")
  | public abstract class MYSUPERCLASS{}

I have entity subclass MYSUBCLASS
-------------------------------------------------------------------
@Entity
  | @DiscriminatorValue("SUBTYPE")
  | public class MYSUBCLASS extends MYSUPERCLASS{
  | }

I have seperate entity class MYCONTAINER that joins contains an object of MYSUBCLASS
-------------------------------------------------------------------
@Entity
  | @Table(name="TABLE_B")
  | public class MYCONTAINER{
  |     private Collection<MYSUBCLASS> mySubCollect;
  | 
  |     @OneToMany(fetch=FetchType.EAGER)
  |     @JoinColumns({...})
  |     public Collection<MYSUBCLASS> getMySubCollect(){
  |         return mySubCollect;
  |     }
  | }


If I do a find on MYSUBCLASS, the sql statement (from the jboss log)performed includes in the where clause: MYSUBCLASS1_.MYDESCRIMCOLUMN = 'SUBTYPE'.  Therefore, my collection is correctly populated with only objects that meet the discrimination criteria.


However, if I do a find on MYCONTAINER, the sql statement performed does NOT include in the where clause: MYSUBCLASS1_.MYDESCRIMCOLUMN = 'SUBTYPE'.  

Here are the results:  Since the descriminator is not part of the query, the hibernate query (extracted from the jboss log) returns 1 row for each row in TABLE_A that matches the join, regardless of whether it meets the criteria of the descriminator.   However, what's even more odd, is that even though the resulting Collection 'mySubCollect' has 1 object for each row in TABLE_A, each of these objects is the same object, representing the first row retrieved.  (If I change my 'mySubCollect' from a Collection to a Set, these multiple rows are compressed into a single row, so it appears that the Collection is getting 1 copy of the same object for each row in the table, regardless of the data in that row.)  

Wierd as heck.  The join doesn't appear to be using the discriminator at all, and is returning the first row retrieved once for each row in the table that matches the join without the discriminator.

We are using EJB3 on JBoss 4.0.4GA, using the Hibernate 3 persistence engine.


If anyone can shine any light on what I am doing wrong, it would be greatly appreciated. 

Thank you!
-Brett Birschbach

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

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



More information about the jboss-user mailing list