我得到ClassCastException: at.sheldor5.tr.api.time.RecordType cannot be cast to java.lang.Boolean
,因为Hibernate 5.2.9.FINAL完全忽略了我的转换器:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="at.sheldor5.tr.api.time">
<class name="Record" table="RECORDS">
<id name="id" type="int" column="PK_RECORD_ID">
<generator class="native"/>
</id>
<many-to-one name="user" column="FK_USER_MAPPING_ID" class="at.sheldor5.tr.api.user.UserMapping"/>
<property name="date" type="java.time.LocalDate" column="DATE" index="I_DATE"/>
<property name="time" type="java.time.LocalTime" column="TIME"/>
<property name="type" type="boolean" column="TYPE">
<type name="at.sheldor5.tr.persistence.converter.RecordTypeAttributeConverter"/>
</property>
</class>
</hibernate-mapping>
转换器:
@Converter
public class RecordTypeAttributeConverter implements AttributeConverter<RecordType, Boolean> {
@Override
public Boolean convertToDatabaseColumn(final RecordType attribute) {
if (attribute == null) {
return null;
}
return attribute.getBoolean();
}
@Override
public RecordType convertToEntityAttribute(final Boolean dbData) {
return RecordType.getType(dbData);
}
}
我唯一能看到的是,由于一些随机的事情,hibernate会忽略我的转换器。
任何建议(除了我已经尝试过的清洁/重建或硬重置)?
编辑:我的转换器甚至无法加载......