Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JpaMetamodelUtils can not find the version attribute if it is in a @MappedSuperclass #1818

Closed
kuhnroyal opened this issue Nov 2, 2023 · 7 comments
Labels
component: core kind: bug worth: high Implementing this has a high worth

Comments

@kuhnroyal
Copy link

Description

I have a version attribute in a @MappedSuperclass but when the EntityView for this class is analyzed, the JpaMetamodelUtils.getVersionAttribute returns null here: https://github.com/Blazebit/blaze-persistence/blob/main/core/parser/src/main/java/com/blazebit/persistence/parser/util/JpaMetamodelUtils.java#L398

The attribute is there but it can not be found by iterating over entityType.getSingularAttributes().
I manually changed the return statement to return entityType.getVersion(Long.class); which succeeds, obviously that only works because I know the type of the field.

Not sure if this only happens with Hibernate 6.2 - I didn't use Blaze before.

Expected behavior

I expect that the version attribute is found so that optimistic locking can be used.

Actual behavior

The version attribute is not found and optimistic locking is disabled.

Steps to reproduce

I will see if I can add that later.

Environment

Version: 1.6.9
JPA-Provider: Hibernate 6.2.13.Final
DBMS: PostgreSQL
Application Server: Java/Spring 6

@kuhnroyal kuhnroyal changed the title JpaMetamodelUtils can not find the version attributed if it is in a @MappedSuperclass JpaMetamodelUtils can not find the version attribute if it is in a @MappedSuperclass Nov 2, 2023
@beikov beikov added kind: bug component: core worth: high Implementing this has a high worth labels Nov 3, 2023
@beikov
Copy link
Member

beikov commented Nov 3, 2023

Thanks for the report. Do you think you could quickly create a reproducer based on our quickstarts?

This quickstart should give you a project template for that purpose:

mvn archetype:generate "-DarchetypeGroupId=com.blazebit" "-DarchetypeArtifactId=blaze-persistence-archetype-entity-view-sample-jakarta" "-DarchetypeVersion=1.6.9"

@kuhnroyal
Copy link
Author

kuhnroyal commented Nov 8, 2023

I managed to boil it down to a simple reproduction: https://github.com/kuhnroyal/blaze-problems/tree/main
The problem seems to happen as soon as more than one subclass entity of the @MappedSuperclass with the version field exists. This might actually be a problem with the Hibernate meta model.

@beikov
Copy link
Member

beikov commented Nov 10, 2023

Thanks so much. Since you dug into this and think this could be a Hibernate ORM issue, would you mind trying to see if you can reproduce an error with just Hibernate ORM?

@kuhnroyal
Copy link
Author

I added a plain HibernateTest

@beikov
Copy link
Member

beikov commented Nov 23, 2023

This is great, thanks for your efforts. Would be awesome if you could create a Hibernate Jira issue so you can also track the efforts for that bug. Also, if you create the issue, please share the link here for cross reference.

@kuhnroyal
Copy link
Author

https://hibernate.atlassian.net/browse/HHH-17465

@beikov
Copy link
Member

beikov commented Nov 27, 2023

Thanks for creating the Jira. I'll try to fix it in Hibernate ORM as soon as possible.

@beikov beikov closed this as completed Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: core kind: bug worth: high Implementing this has a high worth
Projects
None yet
Development

No branches or pull requests

2 participants