users@glassfish.java.net

JPA/Topling Single Table Inheritance issue

From: <glassfish_at_javadesktop.org>
Date: Tue, 24 Apr 2007 18:39:15 PDT

GF v1b14, JDK 1.5

I have 4 separate classes.

Territory, TerritorySet, TerritorySetPrimary, TerritorySetGenerated.

TerritorySet is an abstract superclass of TerritorySetPrimary and TerritorySetGenerated.

These are the pertinent details of the 3 classes.
[code]
@javax.persistence.Entity
@Table(name = "JCTERRITORYSET")
@Inheritance(strategy = javax.persistence.InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "generated", discriminatorType = DiscriminatorType.INTEGER, length = 1)
public abstract class TerritorySet implements Serializable {

    @Id
    @Column(name = "JCTERRITORYSETKEY", nullable = false)
    private Integer territorySetKey;

    @Column(name = "GENERATED", nullable = false)
    private short generated;

    @JoinColumn(name = "JCTERRITORYKEY", referencedColumnName = "JCTERRITORYKEY")
    @ManyToOne
    protected Territory parentTerritory;

    @JoinColumn(name = "CHILDTERRITORYKEY", referencedColumnName = "JCTERRITORYKEY")
    @ManyToOne
    private Territory childTerritory;

...getters and setters ellided...
 }

@javax.persistence.Entity
@Table(name = "JCTERRITORYSET")
@DiscriminatorValue(value = "0")

public class TerritorySetPrimary extends TerritorySet {
    
    /** Creates a new instance of TerritorySetPrimary */
    public TerritorySetPrimary() {
    }
    
}

@javax.persistence.Entity
@Table(name = "JCTERRITORYSET")
@DiscriminatorValue(value = "1")
public class TerritorySetGenerated extends TerritorySet {
    
    /** Creates a new instance of TerritorySetGenerated */
    public TerritorySetGenerated() {
    }
}

[/code]

As you can see, TerritorySetPrimary and TerritorySetGenerated are basically the same thing with the GENERATED field being the only difference.

The reason for this is I want this in my Territory class:

[code]
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "parentTerritory")
    private List<TerritorySetPrimary> primaryTerritories;
[/code]

Essentially, I want a colleciton of only the Primary territories (generated == 0) for this Territory.

The problem I'm having is when I deploy to GFv1b14, I get this:
[code]
Exception [TOPLINK-7154] (Oracle TopLink Essentials - 2006.8 (Build 060830)):
oracle.toplink.essentials.exceptions.ValidationException

Exception Description: The attribute [primaryTerritories] in entity class [class
pkg.entities.Territory] has a mappedBy value of [parentTerritory] which does not exist in
its owning entity class [class pkg.entities.TerritorySetPrimary]. If the owning entity
class is a @MappedSuperclass, this is invalid, and your attribute should reference the
correct subclass.
[/code]

Now, as you can see, there IS a parentTerritory (and an associate get/setter) in the parent TerritorySet class. I even tried making the super class member protected and explicitly adding the get/setter to the subclass, but that did not work either.

So, I'm confused why I am getting this error message and was hoping someone could show the way.
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=214122