Marco Belladelli (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=637b480...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYjYzY2QwYmVi...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16157?atlOrigin=eyJpIjoiYjYzY2...
) HHH-16157 (
https://hibernate.atlassian.net/browse/HHH-16157?atlOrigin=eyJpIjoiYjYzY2...
) Query with join fetch on collection of entities with @DiscriminatorValue causes
duplicate condition (
https://hibernate.atlassian.net/browse/HHH-16157?atlOrigin=eyJpIjoiYjYzY2...
)
Issue Type: Bug Affects Versions: 6.2.0.CR2 Assignee: Marco Belladelli (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=637b480...
) Created: 09/Feb/2023 06:16 AM Priority: Minor Reporter: Marco Belladelli (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=637b480...
)
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'
(
https://hibernate.atlassian.net/browse/HHH-16157#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16157#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100215- sha1:a0f3b6a )