如何使用Hibernate工具通过注解生成域对象。

9
我使用Eclipse Hibernate Tools从我的数据库创建域类,并需要添加JPA注释。
有没有一种方法可以添加注释?可能是通过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;
    }
        ...
1个回答

14

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接