Generate entities from tables with JBossTools

0

I created a JPA project and from the JPA Tools > Generate Entities from Tables I want to generate entities for each table in my database.

I tried to follow a tutorial on the Eclipse website, however it did not work. I believe the tutorial was made in a different version of JBoss Tools than I'm using, since the one I'm using presents a different configuration screen as can be seen in the image. I use the version of JBoss Tools 4.2.2.Final.

How do I properly fill this screen to create my entities?

    
asked by anonymous 23.03.2015 / 22:00

1 answer

0

"In the middle of the road I had a stone. had a stone in the middle
had a stone in the middle of the road had a stone [...] " Carlos Drummond de Andrade

Joking aside, I found the reason I could not do the setup. I made a brief step by step that will help those with the same problem or for those who come across it.

INSTRUCTIONS

  • Create a JPA project in new > JPA Project ;

  • Configure the Projetct name fields with the name of your project; the Target runtime field with the version of your runtime; and in the Configuration field choose the Basic JPA Configuration option and click the Next button

OntheJPAFacetscreen(twoscreensaftertheJPAProjectscreen)youshould:

  • ClickAddconnectionandconfigureaconnectiontoyourdatabase;Afterthat,justclicktheFinishbutton;

Ready now your JPA project is already set up and ready for the generation of your entities. Now just turn on the JPA Tools > Generate Entities from Tables by right clicking on the project. The result is figure below. You select the tables and the tool creates the entities already mapped to you. Incredible appeal!

Thecodebelowshowstheauthorentitycodecreatedfromtheauthortableandtherelationshipswiththistable:

packagemodel;importjava.io.Serializable;importjavax.persistence.*;importjava.util.List;/***Thepersistentclassfortheautordatabasetable.**/@Entity@Table(name="autor")
@NamedQuery(name="Autor.findAll", query="SELECT a FROM Autor a")
public class Autor implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    private String nome;

    //bi-directional many-to-one association to AutorLivro
    @OneToMany(mappedBy="autor")
    private List<AutorLivro> autorLivros;

    public Autor() {
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNome() {
        return this.nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public List<AutorLivro> getAutorLivros() {
        return this.autorLivros;
    }

    public void setAutorLivros(List<AutorLivro> autorLivros) {
        this.autorLivros = autorLivros;
    }

    public AutorLivro addAutorLivro(AutorLivro autorLivro) {
        getAutorLivros().add(autorLivro);
        autorLivro.setAutor(this);

        return autorLivro;
    }

    public AutorLivro removeAutorLivro(AutorLivro autorLivro) {
        getAutorLivros().remove(autorLivro);
        autorLivro.setAutor(null);

        return autorLivro;
    }

}

References

24.03.2015 / 21:26