[jboss-user] [EJB 3.0] - @DiscriminatorValue: find not returning subclasses

lpmon do-not-reply at jboss.com
Thu Dec 27 15:54:30 EST 2007


Env: JBoss AS 4.0.5.GA w/EJB3

I have looked over several different docs that describe how to use entity inheritance w/ SINGLE_TABLE.  I used those examples as the basis for my code.  I have a base class Units and have subclasses RFUnit and EMUnit.

(em is an entitymanager object) 

When I do em.find() or em.getResultList() it always returns the base class.  I get no errors of any kind.  I am examining the returned class by both returnedObject.getClass().getName() and via Eclipse debugger.

Anyone: Please advise as to how to get subclasses returned from em find or query????

Here are the relevant class declarations:

// base class
@Entity
@Table(name = "units", catalog = "test2", uniqueConstraints = @UniqueConstraint(columnNames = "unitName"))
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="hwModel", discriminatorType=DiscriminatorType.INTEGER)
.....
// 1st subclass
@Entity
@DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue(value="3")
public class RFUnit extends Units {
.....

// 2nd subclass
@Entity
@DiscriminatorColumn(name="hwModel", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue(value="7")
public class EMUnit extends RFUnit {
......

// code doing find/fetch
UnitsList ul = new UnitsList(); // Seam convenience class
List l = ul.getResultList();
		
for (Units u:l)
{
	String tmp = u.getClass().getName();
	System.out.println(u.getClass().getName());
}
	
I also tried:

ul.getEntityManager().createQuery("Select units from Units units").getResultList();    to do the fetch.  Same result.

This should be simple.  What am I missing?
I did confirm the discriminator column values where as specified in the @DiscriminatorValue annotation.

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

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



More information about the jboss-user mailing list