Jan Friedrich (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMjEyYTc2MDM0...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16934?atlOrigin=eyJpIjoiMjEyYT...
) HHH-16934 (
https://hibernate.atlassian.net/browse/HHH-16934?atlOrigin=eyJpIjoiMjEyYT...
) Fetching multiple fields of the same base class with InheritanceType.SINGLE_TABLE throws
PropertyAccessException (
https://hibernate.atlassian.net/browse/HHH-16934?atlOrigin=eyJpIjoiMjEyYT...
)
Issue Type: Bug Affects Versions: 6.2.5 Assignee: Unassigned Components: hibernate-core
Created: 13/Jul/2023 06:55 AM Priority: Major Reporter: Jan Friedrich (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%...
)
We are using a single address table with InheritanceType.SINGLE_TABLE and a simple
discriminator value:
@Entity
@Table(name = "CUSTOMER_ADDRESS")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="address_type", discriminatorType =
DiscriminatorType.STRING)
public abstract class CustomerAddressEntity {...}
@Entity
@DiscriminatorValue("H")
public class CustomerAddressLegalEntity extends CustomerAddressEntity {...}
@Entity
@DiscriminatorValue("V")
public class CustomerAddressMailingEntity extends CustomerAddressEntity {...}
We are using a query that selects a single case, the customer assigned to the case and the
addresses of the customer:
SELECT ca
FROM CaseEntity ca
LEFT JOIN FETCH ca.customer cu
LEFT JOIN FETCH cu.customerAddressLegal cal
LEFT JOIN FETCH cu.customerAddressMailing cam
WHERE ca.caseId = :caseId
When we used Spring Boot 2.x, the generated SQL contained joins like this:
left outer join
customer_address customerad14_
on customeren12_.customer_id=customerad14_.customer_id
and customerad14_.address_type='V'
After switching to Spring Boot 3.x / Hibernate 6.x, the SQL looks like this - the
condition on the discriminator column is missing:
from
case c1_0
left join
customer c2_0
on c2_0.customer_id=c1_0.customer_id
left join
customer_address c3_0
on c2_0.customer_id=c3_0.customer_id
left join
customer_address c4_0
on c2_0.customer_id=c4_0.customer_id
where
c1_0.case_id=?
An exception is thrown:
Caused by: org.hibernate.PropertyAccessException: Could not set value of type
[my.package.CustomerAddressLegalEntity] :
`my.package.CustomerEntity.customerAddressMailing` (setter)
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:86)
at
org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:4187)
at
org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.initializeEntityInstance(AbstractEntityInitializer.java:844)
at
org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.initializeEntity(AbstractEntityInitializer.java:804)
at
org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.initializeInstance(AbstractEntityInitializer.java:790)
at
org.hibernate.sql.results.internal.InitializersList.initializeInstance(InitializersList.java:70)
at
org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(StandardRowReader.java:111)
at
org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:87)
at
org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:199)
at
org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:33)
at
org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:361)
at
org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:168)
at
org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(JdbcSelectExecutorStandardImpl.java:93)
at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:31)
at
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.lambda$new$0(ConcreteSqmSelectQueryPlan.java:110)
at
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:303)
at
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:244)
at org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:518)
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:367)
at
org.hibernate.query.spi.AbstractSelectionQuery.getSingleResult(AbstractSelectionQuery.java:473)
(
https://hibernate.atlassian.net/browse/HHH-16934#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16934#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#100231- sha1:2991753 )