2013-07-26 43 views
4

我使用Eclipse Hibernate Tools從我的數據庫開始創建域類,並需要添加JPA註釋。如何使用Hibernate工具生成帶註釋的域對象

有沒有添加註釋的方法?可能與reveng.xml和逆向工程?這應該怎麼做?

生成的域代碼:

public class Country implements java.io.Serializable { 

    private long id; 
    private String description; 
    private String identifier; 
    private String futureuse; 
    private Set accounts = new HashSet(0); 

    public Country() { 
    } 

    public Country(long id, String description, String identifier) { 
     this.id = id; 
     this.description = description; 
     this.identifier = identifier; 
    } 
    ... 

所需的代碼:

@Entity 
@Table(name = "COUNTRY") 
public class Country implements java.io.Serializable { 

    @Id 
    @Column(name="CNTR_ID") 
    private Long id; 
    @Column(name="CNTR_FUTUREUSE") 
    private String futureUse; 
    @Column(name="CNTR_IDENTIFIER") 
    private String identifier; 
    @Column(name="CNTR_DESCRIPTION") 
    private String description; 
    private Set accounts = new HashSet(0); 

    public Country() { 
    } 

    public Country(long id, String description, String identifier) { 
     this.id = id; 
     this.description = description; 
     this.identifier = identifier; 
    } 
     ... 

回答

12

我個人不使用Hibernate的工具,因爲我用的Spring Roo很高興。不過,谷歌搜索帶給我這個。

大多數情況下,mkyong.com提供了一個很好的教程。如果您轉到「Hibernate透視圖」並在「導出」選項卡中單擊「代碼生成配置」,則會出現「生成EJB3註釋」複選框。

http://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/

這在以前的答案被進一步證實。

Can Hibernate tool generate JPA POJO?

相關問題