2011-02-03 122 views
0

它按照我的要求在数据库中存储整数而不是字符串。为什么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 ; 
} 

我知道这应该工作。有任何想法吗?

+0

正如你所说,应该工作得很好。适用于其他JPA提供商(例如DataNucleus) – DataNucleus 2011-02-03 07:51:42

回答

1

一个可能的原因是您的@Enumerated注释不起作用,因为BaseModel中的注释放置在属性上而不是字段上。在字段或属性上放置注释应该在继承层次上保持一致。