Search in sources :

Example 6 with MappingMetamodelImplementor

use of org.hibernate.metamodel.spi.MappingMetamodelImplementor in project hibernate-orm by hibernate.

the class TimeZoneMappingTests method verifyMappings.

@Test
public void verifyMappings(SessionFactoryScope scope) {
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final JdbcTypeRegistry jdbcRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry();
    final EntityPersister entityDescriptor = mappingMetamodel.findEntityDescriptor(EntityWithTimeZone.class);
    final BasicAttributeMapping duration = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("timeZone");
    final JdbcMapping jdbcMapping = duration.getJdbcMapping();
    assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(TimeZone.class));
    assertThat(jdbcMapping.getJdbcType(), equalTo(jdbcRegistry.getDescriptor(Types.VARCHAR)));
    scope.inTransaction((session) -> {
        session.persist(new EntityWithTimeZone(1, TimeZone.getDefault()));
    });
    scope.inTransaction((session) -> session.find(EntityWithTimeZone.class, 1));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) TimeZone(java.util.TimeZone) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) JdbcTypeRegistry(org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry) Test(org.junit.jupiter.api.Test)

Example 7 with MappingMetamodelImplementor

use of org.hibernate.metamodel.spi.MappingMetamodelImplementor in project hibernate-orm by hibernate.

the class ZonedDateTimeMappingTests method verifyMappings.

@Test
public void verifyMappings(SessionFactoryScope scope) {
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.findEntityDescriptor(EntityWithZonedDateTime.class);
    final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("zonedDateTime");
    final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
    assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(ZonedDateTime.class));
    assertThat(jdbcMapping.getJdbcType().getJdbcTypeCode(), isOneOf(Types.TIMESTAMP, Types.TIMESTAMP_WITH_TIMEZONE));
    scope.inTransaction((session) -> {
        session.persist(new EntityWithZonedDateTime(1, ZonedDateTime.now()));
    });
    scope.inTransaction((session) -> session.find(EntityWithZonedDateTime.class, 1));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) ZonedDateTime(java.time.ZonedDateTime) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) Test(org.junit.jupiter.api.Test)

Example 8 with MappingMetamodelImplementor

use of org.hibernate.metamodel.spi.MappingMetamodelImplementor in project hibernate-orm by hibernate.

the class BitSetConverterMutabilityTests method verifyMappings.

@Test
public void verifyMappings(SessionFactoryScope scope) {
    final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.findEntityDescriptor(Product.class);
    final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("bitSet");
    assertThat(attributeMapping.getJavaType().getJavaTypeClass(), equalTo(BitSet.class));
    assertThat(attributeMapping.getValueConverter(), instanceOf(JpaAttributeConverter.class));
    final JpaAttributeConverter converter = (JpaAttributeConverter) attributeMapping.getValueConverter();
    assertThat(converter.getConverterBean().getBeanClass(), equalTo(BitSetConverter.class));
    Assertions.assertThat(attributeMapping.getExposedMutabilityPlan()).isInstanceOf(BitSetMutabilityPlan.class);
    assertThat(attributeMapping.getJdbcMapping().getJdbcType().getJdbcTypeCode(), isOneOf(Types.VARCHAR, Types.NVARCHAR));
    assertThat(attributeMapping.getJdbcMapping().getJavaTypeDescriptor().getJavaTypeClass(), equalTo(String.class));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) JpaAttributeConverter(org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) BitSet(java.util.BitSet) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) Test(org.junit.jupiter.api.Test)

Example 9 with MappingMetamodelImplementor

use of org.hibernate.metamodel.spi.MappingMetamodelImplementor in project hibernate-orm by hibernate.

the class FloatMappingTests method testMappings.

@Test
public void testMappings(SessionFactoryScope scope) {
    // first, verify the type selections...
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.findEntityDescriptor(EntityOfFloats.class);
    {
        final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapper");
        assertThat(attribute.getJavaType().getJavaTypeClass(), equalTo(Float.class));
        final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Float.class));
        assertThat(jdbcMapping.getJdbcType().getJdbcTypeCode(), isOneOf(Types.FLOAT, Types.REAL, Types.NUMERIC));
    }
    {
        final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitive");
        assertThat(attribute.getJavaType().getJavaTypeClass(), equalTo(Float.class));
        final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Float.class));
        assertThat(jdbcMapping.getJdbcType().getJdbcTypeCode(), isOneOf(Types.FLOAT, Types.REAL, Types.NUMERIC));
    }
    // and try to use the mapping
    scope.inTransaction((session) -> session.persist(new EntityOfFloats(1, 3.0F, 5.0F)));
    scope.inTransaction((session) -> session.get(EntityOfFloats.class, 1));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) Test(org.junit.jupiter.api.Test)

Example 10 with MappingMetamodelImplementor

use of org.hibernate.metamodel.spi.MappingMetamodelImplementor in project hibernate-orm by hibernate.

the class InstantMappingTests method verifyMappings.

@Test
public void verifyMappings(SessionFactoryScope scope) {
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.findEntityDescriptor(EntityWithInstant.class);
    final BasicAttributeMapping duration = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("instant");
    final JdbcMapping jdbcMapping = duration.getJdbcMapping();
    assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Instant.class));
    assertThat(jdbcMapping.getJdbcType().getJdbcTypeCode(), equalTo(Types.TIMESTAMP));
    scope.inTransaction((session) -> {
        session.persist(new EntityWithInstant(1, Instant.now()));
    });
    scope.inTransaction((session) -> session.find(EntityWithInstant.class, 1));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) Instant(java.time.Instant) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) Test(org.junit.jupiter.api.Test)

Aggregations

MappingMetamodelImplementor (org.hibernate.metamodel.spi.MappingMetamodelImplementor)49 EntityPersister (org.hibernate.persister.entity.EntityPersister)40 Test (org.junit.jupiter.api.Test)37 BasicAttributeMapping (org.hibernate.metamodel.mapping.internal.BasicAttributeMapping)36 JdbcMapping (org.hibernate.metamodel.mapping.JdbcMapping)29 JdbcTypeRegistry (org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry)14 BitSet (java.util.BitSet)7 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)6 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)4 Dialect (org.hibernate.dialect.Dialect)3 Type (org.hibernate.type.Type)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EntityNameResolver (org.hibernate.EntityNameResolver)2 HibernateException (org.hibernate.HibernateException)2 CollectionDataAccess (org.hibernate.cache.spi.access.CollectionDataAccess)2 SoftLock (org.hibernate.cache.spi.access.SoftLock)2 EntityEntry (org.hibernate.engine.spi.EntityEntry)2 JpaAttributeConverter (org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter)2 NamedTableReference (org.hibernate.sql.ast.tree.from.NamedTableReference)2