Skip to content

Commit

Permalink
HHH-17465 Incorrect metamodel for shared version attribute in @Mapped…
Browse files Browse the repository at this point in the history
…Superclass
  • Loading branch information
beikov committed Aug 7, 2024
1 parent e54a6e1 commit 263ef56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,10 @@ private static void bindVersionProperty(
final org.hibernate.mapping.MappedSuperclass superclass =
getMappedSuperclassOrNull( declaringClass, inheritanceStatePerClass, context );
if ( superclass != null ) {
superclass.setDeclaredVersion( property );
// Don't overwrite an existing version property
if ( superclass.getDeclaredVersion() == null ) {
superclass.setDeclaredVersion( property );
}
}
else {
//we know the property is on the actual entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.util.ServiceRegistryUtil;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -413,6 +414,17 @@ public void testBackrefAndGenerics(EntityManagerFactoryScope scope) {
assertEquals(collectionElement, child);
}

@Test
@Jira("https://hibernate.atlassian.net/browse/HHH-17465")
public void testInheritedVersion(EntityManagerFactoryScope scope) {
EntityManagerFactory emf = scope.getEntityManagerFactory();
assertNotNull(emf.getMetamodel());
final EntityType<Cat> entityType = emf.getMetamodel().entity(Cat.class);
assertTrue(entityType.hasVersionAttribute());
assertTrue(entityType.getSingularAttribute("version").isVersion());

}

private void ensureProperMember(Set<?> attributes) {
//we do not update the set so we are safe
@SuppressWarnings("unchecked") final Set<Attribute<?, ?>> safeAttributes = (Set<Attribute<?, ?>>) attributes;
Expand Down

0 comments on commit 263ef56

Please sign in to comment.