mysql - 为什么这个 JPA 枚举不起作用?

标签 mysql hibernate jpa enums

它在数据库中存储一个整数,而不是我请求的字符串。

这是包含枚举的类。

@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/

相关文章:

java - EntityManager 抛出 @OnetoMany 映射异常

php - 并非所有行都输出 PHP Mysql

python - 棘手的 MySQL 查询而不是 Python 脚本来实现结果?

php - 合并两个准备好的语句不起作用

php - 在不使用 serialize() 或 json_encode() 的情况下在 MySQL 中存储 UTF-8 PHP 数组

java - hibernate : key '173-604' 的重复条目 'PRIMARY'

java - hibernate和oracle的批量插入模式: seems to be dropping back to slow mode silently

java - 防止单个表使用缓存

java - Hibernate 返回两个 Pojo 并使用 jSTL 在 jsp 上显示结果

java - 在 Google App Engine 上使用 JPA 加载子实体