如何使用休眠工具生成带注释的域对象 [英] How to generate domain objects with annotations using hibernate tools

查看:24
本文介绍了如何使用休眠工具生成带注释的域对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

生成的域代码:

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

推荐答案

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

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

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

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".

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

这在之前的答案中得到了进一步证实.

This was further confirmed in previous answers.

Hibernate 工具能否生成 JPA POJO?

这篇关于如何使用休眠工具生成带注释的域对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆