繁体   English   中英

如何使用hibernate工具生成带注释的域对象

[英]How to generate domain objects with annotations using hibernate tools

我使用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;
    }
        ...

我个人不使用hibernate工具,因为我对Spring Roo非常满意。 然而,谷歌搜索带我到这里。

大多数情况下,mkyong.com提供了一个很好的教程。 如果转到“Hibernate perspective”并单击“Export”选项卡中的“Code generation configuration”,则会出现“Generate EJB3 annotations”复选框。

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

这在以前的答案中得到进一步证实。

Hibernate工具可以生成JPA POJO吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM