question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hibernate 'could not resolve property' issue with Composite ID / @IdClass

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
beikovcommented, Jan 26, 2022

In the Apiman upstream we’re using Hibernate 5.3.20.Final – we generally track the version being used in the version of WildFly we support. I suppose I could try to force it to use a different version by using jboss modules, but I am not sure if that will break something else.

Ughh, I feared that this could be the case.

This particular relationship I’ve distilled in the reproducer has been in use in Apiman since about 2014 from what I can see. So I guess the limitation only impacts applications such as BlazePersistence? It seems to have worked for years in terms of using Hibernate itself.

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.

1reaction
beikovcommented, Jan 26, 2022

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hibernate Criteria with composite-id - could not resolve property
I'm using Hibernate 4.3.2.Final and in the mapping.xml, I have a composite id like this: <class name="OrganisationSpecialist" ...
Read more >
Composite primary key-Exception:could not resolve property
My problem is that I split my manytomany relations into two onetomany relations, but when I query datas using Criteria , the code...
Read more >
[Closed] could not resolve property - Genuitec
When I reverse engineer for Hibernate, I get the following: ... catalog="test"> <composite-id name="id" class="com.col.hibernate.
Read more >
org.hibernate.QueryException: could not resolve property
Issue. An entity is defined with a composite (multi-property) identifier/key. Raw. @Entity(name = "Person") @IdClass(PersonId.class) public ...
Read more >
Hibernate ORM 5.4.33.Final User Guide - Red Hat on GitHub
However, unlike many other persistence solutions, Hibernate does not hide the ... Modeling a composite identifier using an IdClass differs from using an ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found