For example, there is base converter class
public abstract class BaseConverter implements AttributeConverter<Bar, Integer>
{
private abstract Bar create(Integer value);
@Override
public Bar convertToEntityAttribute(Integer t) {
return create(t);
}
@Override
public Integer convertToDatabaseColumn(Bar t) {
return t.toInteger();
}
}
and child class, with Converter annotation.
@Converter
public abstract class ConverterImpl extends BaseConverter
{
@Override
private Bar create(Integer value)
{
return Bar.create(value);
}
}
The problem is, when you try to convert field with ConverterImpl, it does not work.
@Column
@Convert(converter = ConverterImpl.class)
public Bar bar;
org.hibernate.AssertionFailure: Could not extract ParameterizedType representation of AttributeConverter definition from AttributeConverter implementation class [ReportScheduleRepeat$Converter] at org.hibernate.cfg.AttributeConverterDefinition.extractAttributeConverterParameterizedType(AttributeConverterDefinition.java:94) at org.hibernate.cfg.AttributeConverterDefinition.<init>(AttributeConverterDefinition.java:52) at org.hibernate.cfg.Configuration.addAttributeConverter(Configuration.java:2690) at org.hibernate.cfg.Configuration.addAttributeConverter(Configuration.java:2641) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1129) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:846) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ... 55 more
Common use case for this is to create generic base converter.
|