use of org.hibernate.metamodel.mapping.internal.BasicAttributeMapping 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));
}
use of org.hibernate.metamodel.mapping.internal.BasicAttributeMapping 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));
}
use of org.hibernate.metamodel.mapping.internal.BasicAttributeMapping 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));
}
use of org.hibernate.metamodel.mapping.internal.BasicAttributeMapping 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));
}
use of org.hibernate.metamodel.mapping.internal.BasicAttributeMapping in project hibernate-orm by hibernate.
the class LocalDateTimeMappingTests method verifyMappings.
@Test
public void verifyMappings(SessionFactoryScope scope) {
final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
final EntityPersister entityDescriptor = mappingMetamodel.findEntityDescriptor(EntityWithLocalDateTime.class);
final BasicAttributeMapping duration = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("localDateTime");
final JdbcMapping jdbcMapping = duration.getJdbcMapping();
assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(LocalDateTime.class));
assertThat(jdbcMapping.getJdbcType().getJdbcTypeCode(), equalTo(Types.TIMESTAMP));
scope.inTransaction((session) -> {
session.persist(new EntityWithLocalDateTime(1, LocalDateTime.now()));
});
scope.inTransaction((session) -> session.find(EntityWithLocalDateTime.class, 1));
}
Aggregations