2013-07-26 44 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?

相关问题