java 如何使用休眠工具生成带注释的域对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17878662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 17:52:45  来源:igfitidea点击:

How to generate domain objects with annotations using hibernate tools

javahibernateobjectannotationshibernate-tools

提问by Dimitri Dewaele

I use Eclipse Hibernate Tools to create domain classes starting from my database and need to add JPA annotations.

我使用 Eclipse Hibernate Tools 从我的数据库开始创建域类,并且需要添加 JPA 注释。

Is there a way to add annotations? Possibly with reveng.xml and Reverse Engineering? How should this be done?

有没有办法添加注释?可能使用 reveng.xml 和逆向工程?这应该怎么做?

Generated domain code:

生成的域代码:

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;
    }
    ...

Needed code:

需要的代码:

@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;
    }
        ...

回答by schomax

I personally don't use hibernate tools, because I'm pretty happy with Spring Roo. However, google search brought me to this.

我个人不使用休眠工具,因为我对 Spring Roo 非常满意。然而,谷歌搜索让我想到了这一点。

As mostly there is a nice tutorial from mkyong.com. If you go to "Hibernate perspective" and click "Code generation configuration" in the "Export" tab there is a checkbox for "Generate EJB3 annotations".

大多数情况下,mkyong.com 上有一个很好的教程。如果您转到“Hibernate 透视图”并单击“导出”选项卡中的“代码生成配置”,则会有一个“生成 EJB3 注释”复选框。

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

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

This was further confirmed in previous answers.

这在之前的回答中得到了进一步证实。

Can Hibernate tool generate JPA POJO?

Hibernate 工具可以生成 JPA POJO 吗?