Hibernate 'could not resolve property' issue with Composite ID / @IdClass
See original GitHub issueDescription
I’m trying to port Apiman to use BlazePersistence instead of the JPA Criteria API to avoid losing my mind with its bizarre syntax 😂.
However, I seem to have hit a blocker.
We use composite keys/ids in our model in a few places via @IdClass
. This is something we can’t change for compatibility reasons (unless there’s a compatible workaround you are aware of).
It seems that the particular @Entity
design we’re using works fine with CriteriaAPI, standard Hibernate, etc, but trips up Blaze Persistence somehow. This may be related to #399, not sure?
The TL;DR is that it seems it can’t traverse that ID properly, and the only thing I can think of is @IdClass
.
Expected behaviour
Should be able to handle this @Entity
sample’s graph, as it works in Hibernate + Criteria API.
Actual behaviour
The error displayed is:
2022-01-25 16:02:15,899 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile dev): org.hibernate.QueryException: could not resolve property: client.id of: io.apiman.manager.api.beans.clients.ClientVersionBean
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:77)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:71)
at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyType(AbstractEntityPersister.java:5124)
at com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.hasJoinCondition(HibernateJpaProvider.java:1414)
at com.blazebit.persistence.impl.EntityMetamodelImpl$AttributeEntry.<init>(EntityMetamodelImpl.java:1060)
at com.blazebit.persistence.impl.EntityMetamodelImpl.collectIdColumns(EntityMetamodelImpl.java:484)
at com.blazebit.persistence.impl.EntityMetamodelImpl.collectColumnNames(EntityMetamodelImpl.java:394)
at com.blazebit.persistence.impl.EntityMetamodelImpl.<init>(EntityMetamodelImpl.java:127)
at com.blazebit.persistence.impl.CriteriaBuilderFactoryImpl.<init>(CriteriaBuilderFactoryImpl.java:110)
at com.blazebit.persistence.impl.CriteriaBuilderConfigurationImpl.createCriteriaBuilderFactory(CriteriaBuilderConfigurationImpl.java:2018)
at com.blazebit.persistence.integration.quarkus.runtime.EntityViewRecorder.lambda$criteriaBuilderFactorySupplier$0(EntityViewRecorder.java:56)
at com.blazebit.persistence.CriteriaBuilderFactory_2f29ab4902e863bcf38a5a9ab37269748362ecdd_Synthetic_Bean.create(Unknown Source)
at com.blazebit.persistence.CriteriaBuilderFactory_2f29ab4902e863bcf38a5a9ab37269748362ecdd_Synthetic_Bean.create(Unknown Source)
at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
at com.blazebit.persistence.CriteriaBuilderFactory_2f29ab4902e863bcf38a5a9ab37269748362ecdd_Synthetic_Bean.get(Unknown Source)
at com.blazebit.persistence.CriteriaBuilderFactory_2f29ab4902e863bcf38a5a9ab37269748362ecdd_Synthetic_Bean.get(Unknown Source)
at org.acme.Main_Bean.create(Unknown Source)
at org.acme.Main_Bean.create(Unknown Source)
at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
at org.acme.Main_Observer_startup_f43ab41051de39ca1e534f6cd06115c3c9b219b8.notify(Unknown Source)
at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:320)
at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:302)
at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:73)
at io.quarkus.arc.runtime.ArcRecorder.fireLifecycleEvent(ArcRecorder.java:128)
at io.quarkus.arc.runtime.ArcRecorder.handleLifecycleEvents(ArcRecorder.java:97)
at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy_0(Unknown Source)
at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy(Unknown Source)
at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
at io.quarkus.runtime.Application.start(Application.java:101)
at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:104)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:67)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:41)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:120)
at io.quarkus.runner.GeneratedMain.main(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.Nati
Steps to reproduce
. https://www.github.com/msavy/reproducer-for-blazepersistence.git
. ./mvnw compile quarkus:dev
(or whatever you prefer).
. First, see Main.java
for bootstrapping, and then io.apiman.manager.api.beans.*
. @IdClass
seems to work in some simpler setups, but not this one.
Environment
Please see reproducer for additional details, but:
Version: 1.6.5
JPA-Provider: Hibernate: 5.6.4
DBMS: com.h2database.h2-1.4.197.jar
Application Server: Quarkus
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
Ughh, I feared that this could be the case.
Well, usually Hibernate allows access to the property types/columns etc. by property path per entity type. So usually, I can ask Hibernate for the type of
client.id
, but it seems that for associations with entitiy types that use an id class, it doesn’t add these property paths.I will implement a workaround for this limitation.
Ok, so I looked into this and unfortunately this is a limitation of Hibernate when it comes to associations for entities with id classes. I created https://hibernate.atlassian.net/browse/HHH-15051 for this and already have a fix for Hibernate ready. I hope it’s ok that you have to update Hibernate to 5.6.6.Final?