You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Manoel Pedro <ms...@gmail.com> on 2014/08/19 03:44:15 UTC

multiple inheritance levels

Is it possible to have "multiple levels" of inheritance?
Consider: Location -> Point -> AbsolutePoint -> GeographicPoint

Using joinded inheritance the discriminator "accumulates", eg:

Relative to Location, Point has just one discriminator "PT", for
AbsolutePoint there is "ABS" relative to Point and "PT" relative to
Location. Tables and classes follow.

(thanks)

"public.loc"
----------+---------------+-----------
 loc_id   | numeric(20,0) | not null
 cat_code | character(6)  | not null
----------+---------------+-----------
"loc_pkey"        PRIMARY KEY, btree (loc_id)
"fk_loc_cat_code" FOREIGN KEY (cat_code) REFERENCES loc_cat_code(code)

"public.point"
----------+---------------+-----------
 point_id | numeric(20,0) | not null
 cat_code | character(6)  | not null
----------+---------------+-----------
"point_pkey" PRIMARY KEY, btree (point_id)
"fk_point_cat_code" FOREIGN KEY (cat_code) REFERENCES point_cat_code(code)
"point_point_id_fkey" FOREIGN KEY (point_id) REFERENCES loc(loc_id)

"public.abs_point"
-----------------------+---------------+-----------------------
 abs_point_id          | numeric(20,0) | not null
 cat_code              | character(6)  | not null
 abs_point_ver_dist_id | numeric(20,0) | default NULL::numeric
-----------------------+---------------+-----------------------
"abs_point_pkey" PRIMARY KEY, btree (abs_point_id)
"fk_point_cat_code" FOREIGN KEY (cat_code) REFERENCES
abs_point_cat_code(code)
"fk_point_id" FOREIGN KEY (abs_point_id) REFERENCES point(point_id)

"public.geo_point"
---------------------+---------------+----------------------
 geo_point_id        | numeric(20,0) | not null
 lat_coord           | numeric(9,6)  | not null
 long_coord          | numeric(10,6) | not null
 lat_precision_code  | character(6)  | default NULL::bpchar
 long_precision_code | character(6)  | default NULL::bpchar
---------------------+---------------+----------------------
"geo_point_pkey" PRIMARY KEY, btree (geo_point_id)
"geo_point_geo_point_id_fkey" FOREIGN KEY (geo_point_id) REFERENCES
abs_point(abs_point_id)

@Entity
@Table(name = "loc")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "cat_code", discriminatorType =
DiscriminatorType.STRING, length = 6)
@DiscriminatorValue("LOC   ")
@XmlRootElement
@XmlSeeAlso({Point.class})
public class Location implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Basic(optional = false, fetch = FetchType.EAGER)
    @NotNull
    @Column(name = "loc_id", precision = 20, scale = 0)
    private BigDecimal locId;

    @ManyToOne(fetch = FetchType.EAGER, optional = true)
    @JoinColumn(name = "cat_code")
    protected LocationCategory locationCategory;
    // ...
}

@Entity
@Table(name = "point")
@DiscriminatorValue("PT    ")
@PrimaryKeyJoinColumn(name = "point_id", referencedColumnName = "loc_id")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "cat_code", discriminatorType =
DiscriminatorType.STRING, length = 6)
@XmlRootElement
@XmlSeeAlso({AbsolutePoint.class})
public class Point extends Location implements Serializable {

    @ManyToOne(optional = true, fetch = FetchType.EAGER)
    @JoinColumn(name = "cat_code")
    private PointCategory pointCategory;
    // ...
}

@Entity
@Table(name = "abs_point")
@DiscriminatorValue("ABS   ")
@PrimaryKeyJoinColumn(name="abs_point_id", referencedColumnName="point_id")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "cat_code",
discriminatorType=DiscriminatorType.STRING, length = 6)
@XmlRootElement
@XmlSeeAlso({GeographicPoint.class})
public class AbsolutePoint extends Point implements Serializable {

    @ManyToOne(fetch = FetchType.EAGER, optional = true)
    @JoinColumn(name = "cat_code")
    private AbsolutePointCategory absPointCategory;
    // ...
}

@Entity
@Table(name = "geo_point")
@DiscriminatorValue("GEOGPT")
@PrimaryKeyJoinColumn(name="geo_point_id",
referencedColumnName="abs_point_id")
@XmlRootElement
public class GeographicPoint extends AbsolutePoint implements Serializable {

    private static final long serialVersionUID = 1L;

    @Basic(optional = false)
    @NotNull
    @Column(name = "lat_coord", precision=9, scale=6)
    private BigDecimal latCoord;
    // ...
}