如何为带有@Convert批注的字段生成MetaModel?

时间:2019-10-15 09:24:21

标签: java hibernate jpa-2.1

我正在尝试使用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<>();

但就我而言,它不是一个集合。

0 个答案:

没有答案