它在数据库中存储一个整数,而不是我请求的字符串。
这是包含枚举的类。
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Document extends BaseModel {
private String title = new String();
private String description = new String();
**@Enumerated(EnumType.STRING)
private DocumentType documentType;**
@Embedded
private DocumentImage documentImage;
// if document should be displayed or published on the web site.
private Boolean published = new Boolean(false);
public Document(DocumentType docType) {
super();
documentType = docType;
setDocumentImage(new DocumentImage());
}
}
这是枚举类:
public enum DocumentType {
policy,procedure,webbookmark,newsrelease,collectionLetter,whitepaper,busform,
newsarticle ;
}
我知道这应该可行。有什么想法吗?
最佳答案
一个可能的原因是您的 @Enumerated
注释未生效,因为 BaseModel
中的注释放置在属性上而不是字段上。字段或属性上的注释的放置在整个继承层次结构中应该保持一致。
关于mysql - 为什么这个 JPA 枚举不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4881791/