Search in sources :

Example 1 with JpaAttributeConverterImpl

use of org.hibernate.metamodel.model.convert.internal.JpaAttributeConverterImpl in project hibernate-orm by hibernate.

the class Converters method jpaAttributeConverter.

/**
 * Generates a BasicValueConverter based on an {@link AttributeConverter}
 */
public static <O, R> BasicValueConverter<O, R> jpaAttributeConverter(JavaType<R> relationalJtd, JavaType<O> domainJtd, Class<? extends AttributeConverter<O, R>> converterClass, SessionFactory factory) {
    final SessionFactoryImplementor sfi = (SessionFactoryImplementor) factory;
    final ManagedBeanRegistry beanRegistry = sfi.getServiceRegistry().getService(ManagedBeanRegistry.class);
    final ManagedBean<? extends AttributeConverter<O, R>> converterBean = beanRegistry.getBean(converterClass);
    final TypeConfiguration typeConfiguration = sfi.getTypeConfiguration();
    final JavaTypeRegistry jtdRegistry = typeConfiguration.getJavaTypeRegistry();
    final JavaType<? extends AttributeConverter<O, R>> converterJtd = jtdRegistry.getDescriptor(converterClass);
    return new JpaAttributeConverterImpl<>(converterBean, converterJtd, domainJtd, relationalJtd);
}
Also used : JavaTypeRegistry(org.hibernate.type.descriptor.java.spi.JavaTypeRegistry) ManagedBeanRegistry(org.hibernate.resource.beans.spi.ManagedBeanRegistry) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) JpaAttributeConverterImpl(org.hibernate.metamodel.model.convert.internal.JpaAttributeConverterImpl) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration)

Aggregations

SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 JpaAttributeConverterImpl (org.hibernate.metamodel.model.convert.internal.JpaAttributeConverterImpl)1 ManagedBeanRegistry (org.hibernate.resource.beans.spi.ManagedBeanRegistry)1 JavaTypeRegistry (org.hibernate.type.descriptor.java.spi.JavaTypeRegistry)1 TypeConfiguration (org.hibernate.type.spi.TypeConfiguration)1