ClassNotFoundException when using hibernate.pamodelgen with named query on the entity
Description
Activity

Gavin King June 19, 2024 at 2:41 PM
This was already fixed in 6.6.0.Alpha1, but is a good candidate for backporting.

Gavin King June 19, 2024 at 2:39 PM
OK, I guess you’re talking about the Maven problem which was fixed by this commit:
Probably that fix should be backported to 6.4/6.5, but on the other hand you’re the first user to actually run into this, so either everyone is using Gradle, or it’s easy to work around.

Fahdi Jbeli June 19, 2024 at 2:15 PM
I could reproduce the issue on a new project without spring. I checked this bug and found it was solved in newer version > 6.4.4, the transitive dependency was changed to compile scope . in our project since I do not prefer to override dependency versions I will override the scope as a workaround till we moved to new version.

Fahdi Jbeli June 19, 2024 at 1:53 PM
In this context spring does not add anything, it has only dependency managements. The hibernate-jpamodelgen
depends transitively on hibernate-common-annotations
which has a runtime scope, the processor is called during compile time, I am wondering how your test could pass on version of 6.4.4 and if you used named query in your entity.
I will try to test without spring.

Gavin King June 19, 2024 at 12:53 PMEdited
I don’t understand. In recent version of Hibernate (since the introduction of compile-time HQL query validation), hibernate-jpamodelgen
has a dependency on hibernate-core
, which in turn depends on hibernate-common-annotations
.
In my projects, when I add hibernate-jpamodelgen
as an annotation processor, this Just Works, and I don’t need to do anything else.
And I’m suspicious, because you immediately start talking about Spring, which leads me to suspect that you didn’t actually try it without Spring before submitting this bug report.
Details
Details
Assignee

Reporter

Having a JPA entity annotated with NamedQuery and
hibernate-jpamodelgen
as dependency in the project, will lead to load classes fromhibernate-commons-annotations
which is a transitive dependency with runtime scope.We use spring boot 3.2 which brings hibernate-core 6.4.4.Final.
Is this a bug or do we have explicitly change the scope of
hibernate-commons-annotations
(which would not be ideal)?