HHH-18841 Create `_identifierMapper` as a synthetic attribute

This commit is contained in:
marko-bekhta 2024-11-11 13:23:59 +01:00 committed by Christian Beikov
parent 1ffde48f5b
commit a26e5059fb
2 changed files with 40 additions and 1 deletions

View File

@ -105,6 +105,7 @@ import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.SingleTableSubclass;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.SyntheticProperty;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.TableOwner;
import org.hibernate.mapping.UnionSubclass;
@ -550,7 +551,7 @@ public class EntityBinder {
propertyAccessor,
isIdClass
);
final Property mapperProperty = new Property();
final Property mapperProperty = new SyntheticProperty();
mapperProperty.setName( NavigablePath.IDENTIFIER_MAPPER_PROPERTY );
mapperProperty.setUpdateable( false );
mapperProperty.setInsertable( false );

View File

@ -0,0 +1,38 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.id.idClass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@DomainModel(
annotatedClasses = MyEntity.class
)
@SessionFactory
public class IdClassSyntheticAttributesTest {
@Jira("https://hibernate.atlassian.net/browse/HHH-18841")
@Test
public void test(DomainModelScope scope) {
final PersistentClass entityBinding = scope.getDomainModel().getEntityBinding(MyEntity.class.getName());
assertThat(entityBinding.getProperties()).hasSize(2)
.anySatisfy(p -> {
assertThat(p.isSynthetic()).isTrue();
assertThat(p.getName()).isEqualTo("_identifierMapper");
})
.anySatisfy(p -> {
assertThat(p.isSynthetic()).isFalse();
assertThat(p.getName()).isEqualTo("notes");
});
}
}