Search in sources :

Example 1 with AttributeConverterDescriptorNonAutoApplicableImpl

use of org.hibernate.boot.internal.AttributeConverterDescriptorNonAutoApplicableImpl in project hibernate-orm by hibernate.

the class AttributeConverterTest method testBasicOperation.

@Test
public void testBasicOperation() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).buildMetadata();
        SimpleValue simpleValue = new SimpleValue(metadata);
        simpleValue.setJpaAttributeConverterDescriptor(new AttributeConverterDescriptorNonAutoApplicableImpl(new StringClobConverter()));
        simpleValue.setTypeUsingReflection(IrrelevantEntity.class.getName(), "name");
        Type type = simpleValue.getType();
        assertNotNull(type);
        if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
            fail("AttributeConverter not applied");
        }
        AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
        assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
        assertEquals(Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) Type(org.hibernate.type.Type) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) IrrelevantEntity(org.hibernate.IrrelevantEntity) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) AttributeConverterDescriptorNonAutoApplicableImpl(org.hibernate.boot.internal.AttributeConverterDescriptorNonAutoApplicableImpl) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 2 with AttributeConverterDescriptorNonAutoApplicableImpl

use of org.hibernate.boot.internal.AttributeConverterDescriptorNonAutoApplicableImpl in project hibernate-orm by hibernate.

the class SimpleValue method setTypeName.

public void setTypeName(String typeName) {
    if (typeName != null && typeName.startsWith(AttributeConverterTypeAdapter.NAME_PREFIX)) {
        final String converterClassName = typeName.substring(AttributeConverterTypeAdapter.NAME_PREFIX.length());
        final ClassLoaderService cls = getMetadata().getMetadataBuildingOptions().getServiceRegistry().getService(ClassLoaderService.class);
        try {
            final Class<AttributeConverter> converterClass = cls.classForName(converterClassName);
            attributeConverterDescriptor = new AttributeConverterDescriptorNonAutoApplicableImpl(converterClass.newInstance());
            return;
        } catch (Exception e) {
            log.logBadHbmAttributeConverterType(typeName, e.getMessage());
        }
    }
    this.typeName = typeName;
}
Also used : AttributeConverter(javax.persistence.AttributeConverter) AttributeConverterDescriptorNonAutoApplicableImpl(org.hibernate.boot.internal.AttributeConverterDescriptorNonAutoApplicableImpl) MappingException(org.hibernate.MappingException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Aggregations

AttributeConverterDescriptorNonAutoApplicableImpl (org.hibernate.boot.internal.AttributeConverterDescriptorNonAutoApplicableImpl)2 AttributeConverter (javax.persistence.AttributeConverter)1 IrrelevantEntity (org.hibernate.IrrelevantEntity)1 MappingException (org.hibernate.MappingException)1 MetadataSources (org.hibernate.boot.MetadataSources)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)1 SimpleValue (org.hibernate.mapping.SimpleValue)1 AbstractStandardBasicType (org.hibernate.type.AbstractStandardBasicType)1 BasicType (org.hibernate.type.BasicType)1 Type (org.hibernate.type.Type)1 AttributeConverterTypeAdapter (org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter)1 Test (org.junit.Test)1