Nicolas Noffke (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5a9bd36...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiN2ExOTI5N2E3...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16247?atlOrigin=eyJpIjoiN2ExOT...
) HHH-16247 (
https://hibernate.atlassian.net/browse/HHH-16247?atlOrigin=eyJpIjoiN2ExOT...
) Criteria Query with Object-Typed Embedded Parameter throws AssertionError (
https://hibernate.atlassian.net/browse/HHH-16247?atlOrigin=eyJpIjoiN2ExOT...
)
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Unassigned Components: query-criteria
Created: 02/Mar/2023 23:08 PM Priority: Major Reporter: Nicolas Noffke (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5a9bd36...
)
The following criteria query where the Parameter’s type is Object and the value is an
Embedded throws an AssertionError. If the parameter is correctly typed it works. For the
Object type Parameter, querying for a simple value like a string also works.
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<WithEmbedded> query = cb.createQuery(WithEmbedded.class);
final Root<WithEmbedded> root = query.from(WithEmbedded.class);
//deliberately using Object type here, using AnEmbeddable works
final ParameterExpression< Object > parameter = cb.parameter( Object.class);
query.select(root).where(cb.equal(root.get( "e" ), parameter));
final TypedQuery<WithEmbedded> typedQuery = entityManager.createQuery(query);
typedQuery.setParameter(parameter, new AnEmbeddable( "a" , "b" ));
typedQuery.getResultList(); // throws AssertionError
java.lang.AssertionError
at org.hibernate.query.sqm.internal.SqmUtil.createValueBindings(SqmUtil.java:401)
at
org.hibernate.query.sqm.internal.SqmUtil.createJdbcParameterBindings(SqmUtil.java:326)
at
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.buildCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:393)
at
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:300)
at
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:276)
at org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:571)
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:363)
at org.hibernate.query.sqm.internal.QuerySqmImpl.list(QuerySqmImpl.java:1073)
at org.hibernate.query.Query.getResultList(Query.java:94)
While this might seem contrived on its own, it happens with the following spring data
code:
@Embeddable
data class AnEmbeddable(@Column(nullable = false) val foo: String, @Column(nullable =
false) val bar: String)
interface HasEmbeddable{
val e: AnEmbeddable
}
@Entity
class WithEmbedded(@Id val id: Long, @Embedded override val e: AnEmbeddable):
HasEmbeddable
@NoRepositoryBean
interface HasEmbeddableRepository<T: HasEmbeddable, ID, in AnEmbeddable> :
JpaRepository<T, ID>{
fun findByE(e: AnEmbeddable): List<WithEmbedded>
}
interface WithEmbeddedRepository: HasEmbeddableRepository<WithEmbedded, Long,
AnEmbeddable>
Please find a hibernate test here:
https://github.com/noffke/criteria-embedded-parameter-test (
https://github.com/noffke/criteria-embedded-parameter-test )
Corresponding test case for spring data:
https://github.com/noffke/spring-data-jpa-embedded-test/blob/master/src/t...
(
https://github.com/noffke/spring-data-jpa-embedded-test/blob/master/src/t...
)
(
https://hibernate.atlassian.net/browse/HHH-16247#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16247#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#100217- sha1:65be9f2 )