I have the following abstract class with property sysProp on it.

   @Table(name="DDB_System")
   @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
   @Entity(name="System")
   public abstract class System
   .....................................
       @Column(name="sysProp1",length=1024)
       @Basic
       private String sysProp1;

System also has multiple subclasses, each with properties of their own:

   @Table(name="ComputerSystem")       ** This has multiple concrete
   subTypes**
   @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
   @DiscriminatorValue(value="ComputerSystem")
   @Entity(name="ComputerSystem")
   public class ComputerSystem extends System
   .....................................
       @Column(name="csProp1",length=1024)
       @Basic
       private String csProp1;

and

   @DiscriminatorValue(value="OperatingSystem")
   @Entity(name="OperatingSystem")
   public class OperatingSystem extends System
   .....................................
       @Column(name="osProp1",length=1024)
       @Basic
       private String osProp1;

I have another entity that is directly related to the "System" abstract
class.

@Table(name="A")
@Entity(name="A")
public class A
........................
    @ManyToOne
    @PrimaryKeyJoinColumn(name="SOURCEID",referencedColumnName="OID")
    private System Source;

When I try to query over this relationship and include a property from the
abstract class, it fails:

"select m from A m where m.Source.sysProp1 = 'z'"
Caused by: <openjpa-1.2.0-r422266:683325 fatal user error>
org.apache.openjpa.persistence.ArgumentException: Cannot join across
"A.Source".  The related type has unjoined subclasses.
      at org.apache.openjpa.jdbc.meta.strats.RelationStrategies.unjoinable(
RelationStrategies.java:53)

If I change the query to include a property from one of the subTypes, it
fails because it doesn't know about that property:
"select m from A m where m.Source.osProp1 = 'z'"
Caused by: <openjpa-1.2.0-r422266:683325 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: An error occurred while
parsing the query filter "select m from A m where m.Source.osProp1 = 'z'".
Error message: No field named "osProp1" in class "class System".
      at
org.apache.openjpa.kernel.exps.AbstractExpressionBuilder.parseException(
AbstractExpressionBuilder.java:118)

An archived post
(http://mail-archives.apache.org/mod_mbox/openjpa-users/200711.mbox/%[email protected]%3e)
 said to add the @Type annotation to relationship property.  When I changed
it to the following, both queries worked as expected:
    @ManyToOne
    @PrimaryKeyJoinColumn(name="SOURCEID",referencedColumnName="OID")
    @Type(OperatingSystem.class)
    private System Source;

My problem is that this lets me set one concrete subType, but I have more
than one.  Is there a way to set multiple.  Any query going to the other
subType still won't work:
"select m from A m where m.Source.csProp1 = 'z'"

  Thanks,

Jeff Awe
 Email: [email protected]
 Dept: ELH  Phone: 507-253-1955    T/L: 553-1955

Reply via email to