If a @OneToMany association with an Entity which has a @DiscriminatorValue is retrieved through a join fetch query the discriminator condition will be duplicated in the generated SQL. Here is a mapping example:
@Entity(name = "Person")
public class Person {
@OneToMany(fetch = FetchType.LAZY, mappedBy = "person")
private Set<Leg> legs = new HashSet<>();
}
@Entity(name = "BodyPart")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "discriminator")
public abstract class BodyPart {
}
@Entity(name = "Leg")
@DiscriminatorValue("LegBodyPart")
public class Leg extends BodyPart {
@ManyToOne(optional = false)
private Person person;
}
Querying with the following JPQL:
select person from Person person left join fetch person.legs as legs
Will produce a SQL select with the duplicated condition:
select
p1_0.id,
l1_0.person_id,
l1_0.id,
l1_0.name,
p1_0.name
from
person p1_0
left join
body_part l1_0
on p1_0.id=l1_0.person_id
and l1_0.discriminator='LegBodyPart'
and l1_0.discriminator='LegBodyPart'
|