How to generate domain objects with annotations using hibernate tools
Asked Answered
H

1

9

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

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

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;
    }
        ...
Hereditable answered 26/7, 2013 at 10:10 Comment(0)
M
14

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

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.

Can Hibernate tool generate JPA POJO?

Marquardt answered 29/7, 2013 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.