为什么这个 JPA 枚举不起作用?
它在数据库中存储一个整数,而不是我请求的字符串。
这是包含枚举的类。
@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 ;
}
我知道这应该可行。有什么想法吗?
It is storing an integer in the database not the string as I requested.
Here is the class that contains the enum.
@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());
}
}
and here is the enum class:
public enum DocumentType {
policy,procedure,webbookmark,newsrelease,collectionLetter,whitepaper,busform,
newsarticle ;
}
I know this should work. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个可能的原因是您的
@Enumerated
注释未生效,因为BaseModel
中的注释放置在属性上而不是字段上。字段或属性上的注释的放置在继承层次结构中应该保持一致。One possible reason is that your
@Enumerated
annotation doesn't take effect because annotations inBaseModel
are placed on properties rather than on fields. Placement of annotations on fields or properties should be consistent across inheritance hierarchy.