"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