我正在尝试使用org.hibernate:hibernate-jpamodelgen
生成MetalModel类,它会跳过标有@Convert
注释的字段,例如:
@Entity
public class Item {
@Column
@Convert(converter = StuffConverter.class)
private Stuff stuff;
}
public class StuffConverter implements AttributeConverter<Stuff, String> {
@Override
public String convertToDatabaseColumn(Stuff attribute) {
// serialize to json
}
@Override
public Stuff convertToEntityAttribute(String dbData) {
// deserialize from json
}
}
有趣的是,如果我用@Basic
注释标记字段内容,它在生成的元模型类中,但是我不确定用@Basic
标记字段是否正确,如文档所述:< / p>
The
* <code>Basic</code> annotation can be applied to a persistent
* property or instance variable of any of the following types: Java
* primitive types, wrappers of the primitive types
... [skipped for brevity]
有趣的是,生成器的单元测试可以在以下情况下进行测试,并且效果很好:
@ElementCollection
@Convert(converter = ItemRoleConverter.class)
private Set<Role> roles = new HashSet<>();
但就我而言,它不是一个集合。