2011-02-03 119 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中的註釋放置在屬性上而不是字段上。在字段或屬性上放置註釋應該在繼承層次上保持一致。