I dont know if this is a bug or there is something I am missing, but there is a problem when you try to use Inheritance.JOINED when the superclass has a composite primary key.
I have the following classes: (Superclass)
@Entity
@Table(name = "tipos_opciones_misiones")
@IdClass(TipoOpcionMisionId.class)
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "clase", discriminatorType = DiscriminatorType.STRING)
@ReadOnly
public abstract class TipoOpcionMision{
@Id
@ManyToOne
@JoinColumn(name="tipo_mision")
private TipoMision tipoMision;
@Id
@Column(name = "numero")
private int numero;
}
And a child class:
@Entity
@Table(name="tipos_misiones_opciones_comercio_compra")
@DiscriminatorValue("COMERCIO_COMPRA")
public class TipoOpcionMisionComercioCompra extends TipoOpcionMision{
@Column(name="valor")
double valor;
}
When I try to get a list on objects "TipoOpcionMision" the generated SQL ignores that there is a composite key [tipo_mision, numero] and it just uses "t1.numero = t0.numero". There should also be a "t1.tipo_mision= t0.tipo_mision".
SELECT **list of fields***, FROM tipos_misiones_opciones t0, tipos_misiones_opciones_comercio_compra t1 WHERE ((t0.tipo_mision = 'MISION_1') AND ((t1.numero = t0.numero) AND (t0.clase = 'COMERCIO_COMPRA')))
There is no errors, but I get false results because I am getting the values of the first row in the cartesian product.
I have tried to add:
@PrimaryKeyJoinColumns({
@PrimaryKeyJoinColumn(name = "tipo_mision", referencedColumnName = "tipo_mision"),
@PrimaryKeyJoinColumn(name = "numero", referencedColumnName = "numero")
})
But program fails when starting with the following error:
Exception Description: A @PrimaryKeyJoinColumns was found on the annotated element [class TipoOpcionMisionComercioCompra]. When the entity uses a single primary key, only a single (or zero) @PrimaryKeyJoinColumn should be specified.
It seems that for some reason Eclipselink is ignoring tthat the superclass has a composite primary key.
[Updated on: Tue, 14 June 2022 22:45]
Report message to a moderator