HHH-17465 Incorrect metamodel for shared version attribute in @MappedSuperclass

This commit is contained in:
Christian Beikov 2024-08-07 17:53:10 +02:00
parent e54a6e15b2
commit 263ef56970
2 changed files with 16 additions and 1 deletions

View File

@ -979,7 +979,10 @@ public class PropertyBinder {
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

View File

@ -29,6 +29,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
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;
@ -413,6 +414,17 @@ public class MetadataTest {
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;