Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Joined Inheritance resulting in incorrect query - change when putting subclasses into same package?

I was trying to work out why some subclasses were working and others giving
me "Missing class for indicator field value" which were present and
apparently identically annotated. To simplify comparisons I put all
subclasses into same package as main class but this seems to have broken
joined table inheritance big time.

        TypedQuery<BoreHole> q = em.createQuery("SELECT x FROM BoreHole x
where x.name = '" + name + "'", BoreHole.class);

generates SQL like SELECT BH_ID, BH_TYPE_ID, etc FROM SC.BORE_HOLE WHERE
((BH_NAME = ?) AND (BH_TYPE_ID = ?))"))
but it always binds the discriminator value of the base borehole class.
(value 5). Ie it is selecting for the particular instance of BoreHole and
not any of the subclasses. I am noob at JPA but this looks like all the
examples I have seen.

The structure is:

@Entity(name="BoreHole")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="BH_TYPE_ID",
discriminatorType=DiscriminatorType.INTEGER)
@DiscriminatorValue("5")
@Table(name="SC.BORE_HOLE")
public class BoreHole implements Serializable {
etc

subclasses are like:
@Entity(name = "GeothermalBore")
@Table(name = "MINERAL.GEOTHERMAL_BORE")
@DiscriminatorValue("8")
@PrimaryKeyJoinColumn(name="BH_ID",referencedColumnName="BH_ID")
public class GeothermalBore extends BoreHole{

@Entity(name = "PetroleumBore")
@Table(name = "PETROLEUM.PETROLEUM_BORE")
@DiscriminatorValue("1")
@PrimaryKeyJoinColumn(name="BH_ID",referencedColumnName="BH_ID")
public class PetroleumBore extends BoreHole{

etc

This seems bizarre behaviour. I suppose I could make BoreHole into an
abstract superclass, but BORE_TYPE_ID = 5 has no joined table so seems
unnecessary. I am loss to understand why the simple refactor into on package
dramatically changed the behaviour (not that previous error was much help
either).

eclipselink 2.5.1





--
View this message in context: http://eclipse.1072660.n5.nabble.com/Joined-Inheritance-resulting-in-incorrect-query-change-when-putting-subclasses-into-same-package-tp171183.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.


Back to the top