use of org.hibernate.type.descriptor.java.MutabilityPlan in project hibernate-orm by hibernate.
the class ExplicitJavaTypeDescriptorTest method testIt.
@Test
@TestForIssue(jiraKey = "HHH-11098")
public void testIt() {
// set up test data
Session session = openSession();
((MetamodelImplementor) session.getMetamodel()).getTypeConfiguration().getJavaTypeDescriptorRegistry().addDescriptor(new JavaTypeDescriptorRegistry.FallbackJavaTypeDescriptor(MutableState2.class) {
@Override
public MutabilityPlan getMutabilityPlan() {
return ImmutableMutabilityPlan.INSTANCE;
}
});
session.beginTransaction();
session.persist(new TheEntity(1));
session.getTransaction().commit();
session.close();
// assertions based on the persist call
// 1 instead of 0 because of the deep copy call
assertThat(mutableToDomainCallCount, is(1));
// 2 instead of 1 because of the deep copy call
assertThat(mutableToDatabaseCallCount, is(2));
// logical
assertThat(immutableToDomainCallCount, is(0));
// logical
assertThat(immutableToDatabaseCallCount, is(1));
// was 1 (like mutable) before the JavaTypeDescriptor registration
assertThat(immutableMutableToDomainCallCount, is(0));
// was 2 (like mutable) before the JavaTypeDescriptor registration
assertThat(immutableMutableToDatabaseCallCount, is(1));
// clean up test data
session = openSession();
session.beginTransaction();
session.delete(session.byId(TheEntity.class).getReference(1));
session.getTransaction().commit();
session.close();
}
Aggregations