Hibernate @ Embedded in @Embeddable ignore annotation?
I'm trying to use @Embeddable
internally annother @Embeddable
which is supported as per spec, however, it looks like the JPA annotation in the class Code
below is being ignored. Enumeration (de) is converted in ordinal order instead of string representation. I can think of a few workarounds, but that's not a problem. I am trying to figure out what I am doing wrong.
I am using hibernate 4.2.5 with Spring 3.2.4
@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;
}
+3
Mzzl
source
to share
1 answer
I can confirm that I have the same error in the newest version of SpringBoot (!!!) 2.1.4.RELEASE Can anyone provide a working way or confirm that this is not a bug?
0
JFCorleone
source
to share