@Embeddable中的Hibernate @Embedded忽略了注释?

时间:2014-09-12 08:54:10

标签: java spring hibernate jpa

我正在尝试使用@Embeddable内部的另一个@Embeddable,这是根据规范支持的,但是,看起来好像以下de Code类中的JPA注释是忽略。枚举由序数而不是字符串表示(de)序列化。我可以想到几个解决方法,但这不是问题。我想知道我做错了什么。

我正在使用带有Spring 3.2.4的hibernate 4.2.5

@Entity
public class ExampleEntity implements Serializable {

    @Id
    @GeneratedValue
    private Long id;

    @ElementCollection(fetch = EAGER)
    @CollectionTable(name="example_embeddable",
            joinColumns=@JoinColumn(name="example_entity_id"))
    private Set<ExampleEmbeddable> embeddables = new HashSet<>();

    // This enum is (de)serialized as a string just fine
    @Enumerated(EnumType.STRING)
    private AnotherEnum another;

    private String stuff;
}

@Embeddable
public class ExampleEmbeddable implements Serializable {

    @Embedded
    private Code code;

    // This enum is (de)serialized as a string just fine
    @Enumerated(EnumType.STRING)
    private StatusEnum status;
}

@Embeddable
public class Code implements Serializable {

    public enum Version {
        RED,
        BLUE,
        GREEN
    }

    private String code;

    //Why is this enum is (de)serialized by ordinal?
    @Enumerated(EnumType.STRING)
    private Version version;
}

0 个答案:

没有答案