Search in sources :

Example 21 with BasicAttributeMapping

use of org.hibernate.metamodel.mapping.internal.BasicAttributeMapping in project hibernate-orm by hibernate.

the class BitSetJdbcTypeCodeTests method verifyMappings.

@Test
public void verifyMappings(SessionFactoryScope scope) {
    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(), nullValue());
    assertThat(attributeMapping.getJdbcMapping().getJdbcType().getJdbcTypeCode(), is(Types.VARBINARY));
    assertThat(attributeMapping.getJdbcMapping().getJavaTypeDescriptor().getJavaTypeClass(), equalTo(BitSet.class));
    scope.inTransaction((session) -> {
        session.persist(new Product(1, BitSet.valueOf(BitSetHelper.BYTES)));
    });
    scope.inSession((session) -> {
        final Product product = session.get(Product.class, 1);
        assertThat(product.getBitSet(), equalTo(BitSet.valueOf(BitSetHelper.BYTES)));
    });
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) BitSet(java.util.BitSet) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) Test(org.junit.jupiter.api.Test)

Example 22 with BasicAttributeMapping

use of org.hibernate.metamodel.mapping.internal.BasicAttributeMapping in project hibernate-orm by hibernate.

the class BitSetJdbcTypeTests method verifyMappings.

@Test
public void verifyMappings(SessionFactoryScope scope) {
    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(), nullValue());
    assertThat(attributeMapping.getJdbcMapping().getJdbcType().getJdbcTypeCode(), is(Types.VARBINARY));
    assertThat(attributeMapping.getJdbcMapping().getJavaTypeDescriptor().getJavaTypeClass(), equalTo(BitSet.class));
    scope.inTransaction((session) -> {
        session.persist(new Product(1, BitSet.valueOf(BitSetHelper.BYTES)));
    });
    scope.inSession((session) -> {
        final Product product = session.get(Product.class, 1);
        assertThat(product.getBitSet(), equalTo(BitSet.valueOf(BitSetHelper.BYTES)));
    });
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) BitSet(java.util.BitSet) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) Test(org.junit.jupiter.api.Test)

Example 23 with BasicAttributeMapping

use of org.hibernate.metamodel.mapping.internal.BasicAttributeMapping in project hibernate-orm by hibernate.

the class LocaleMappingTests 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(EntityWithLocale.class);
    final BasicAttributeMapping duration = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("locale");
    final JdbcMapping jdbcMapping = duration.getJdbcMapping();
    assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Locale.class));
    assertThat(jdbcMapping.getJdbcType(), equalTo(jdbcRegistry.getDescriptor(Types.VARCHAR)));
    scope.inTransaction((session) -> {
        session.persist(new EntityWithLocale(1, Locale.US));
    });
    scope.inTransaction((session) -> session.find(EntityWithLocale.class, 1));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) Locale(java.util.Locale) 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 24 with BasicAttributeMapping

use of org.hibernate.metamodel.mapping.internal.BasicAttributeMapping in project hibernate-orm by hibernate.

the class ShortMappingTests 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(EntityOfShorts.class);
    {
        final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapper");
        assertThat(attribute.getJavaType().getJavaTypeClass(), equalTo(Short.class));
        final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Short.class));
        assertThat(jdbcMapping.getJdbcType().getJdbcTypeCode(), is(Types.SMALLINT));
    }
    {
        final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitive");
        assertThat(attribute.getJavaType().getJavaTypeClass(), equalTo(Short.class));
        final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Short.class));
        assertThat(jdbcMapping.getJdbcType().getJdbcTypeCode(), is(Types.SMALLINT));
    }
    // and try to use the mapping
    scope.inTransaction((session) -> session.persist(new EntityOfShorts(1, (short) 3, (short) 5)));
    scope.inTransaction((session) -> session.get(EntityOfShorts.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 25 with BasicAttributeMapping

use of org.hibernate.metamodel.mapping.internal.BasicAttributeMapping in project hibernate-orm by hibernate.

the class ZoneOffsetMappingTests 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(EntityWithZoneOffset.class);
    final BasicAttributeMapping duration = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("zoneOffset");
    final JdbcMapping jdbcMapping = duration.getJdbcMapping();
    assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(ZoneOffset.class));
    assertThat(jdbcMapping.getJdbcType(), equalTo(jdbcRegistry.getDescriptor(Types.VARCHAR)));
    scope.inTransaction((session) -> {
        session.persist(new EntityWithZoneOffset(1, ZoneOffset.from(ZoneOffset.MIN)));
    });
    scope.inTransaction((session) -> session.find(EntityWithZoneOffset.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) JdbcTypeRegistry(org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry) ZoneOffset(java.time.ZoneOffset) Test(org.junit.jupiter.api.Test)

Aggregations

BasicAttributeMapping (org.hibernate.metamodel.mapping.internal.BasicAttributeMapping)41 Test (org.junit.jupiter.api.Test)40 EntityPersister (org.hibernate.persister.entity.EntityPersister)39 MappingMetamodelImplementor (org.hibernate.metamodel.spi.MappingMetamodelImplementor)36 JdbcMapping (org.hibernate.metamodel.mapping.JdbcMapping)29 JdbcTypeRegistry (org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry)17 BitSet (java.util.BitSet)7 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 JpaAttributeConverter (org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter)4 ZoneOffset (java.time.ZoneOffset)2 Dialect (org.hibernate.dialect.Dialect)2 NationalizationSupport (org.hibernate.dialect.NationalizationSupport)2 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)2 ModelPart (org.hibernate.metamodel.mapping.ModelPart)2 BasicValueConverter (org.hibernate.metamodel.model.convert.spi.BasicValueConverter)2 Duration (java.time.Duration)1 Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1