Skip to content

Commit 263ef56

Browse files
committed
HHH-17465 Incorrect metamodel for shared version attribute in @MappedSuperclass
1 parent e54a6e1 commit 263ef56

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,10 @@ private static void bindVersionProperty(
979979
final org.hibernate.mapping.MappedSuperclass superclass =
980980
getMappedSuperclassOrNull( declaringClass, inheritanceStatePerClass, context );
981981
if ( superclass != null ) {
982-
superclass.setDeclaredVersion( property );
982+
// Don't overwrite an existing version property
983+
if ( superclass.getDeclaredVersion() == null ) {
984+
superclass.setDeclaredVersion( property );
985+
}
983986
}
984987
else {
985988
//we know the property is on the actual entity

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metadata/MetadataTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.hibernate.testing.TestForIssue;
3131
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
32+
import org.hibernate.testing.orm.junit.Jira;
3233
import org.hibernate.testing.orm.junit.Jpa;
3334
import org.hibernate.testing.util.ServiceRegistryUtil;
3435
import org.junit.jupiter.api.Test;
@@ -413,6 +414,17 @@ public void testBackrefAndGenerics(EntityManagerFactoryScope scope) {
413414
assertEquals(collectionElement, child);
414415
}
415416

417+
@Test
418+
@Jira("https://hibernate.atlassian.net/browse/HHH-17465")
419+
public void testInheritedVersion(EntityManagerFactoryScope scope) {
420+
EntityManagerFactory emf = scope.getEntityManagerFactory();
421+
assertNotNull(emf.getMetamodel());
422+
final EntityType<Cat> entityType = emf.getMetamodel().entity(Cat.class);
423+
assertTrue(entityType.hasVersionAttribute());
424+
assertTrue(entityType.getSingularAttribute("version").isVersion());
425+
426+
}
427+
416428
private void ensureProperMember(Set<?> attributes) {
417429
//we do not update the set so we are safe
418430
@SuppressWarnings("unchecked") final Set<Attribute<?, ?>> safeAttributes = (Set<Attribute<?, ?>>) attributes;

0 commit comments

Comments
 (0)