"In the middle of the road there was a stone
had a stone in the way
had a stone
in the middle of the road there was a stone[...]" Carlos Drummond de Andrade
Joking aside, I found the reason I couldn’t make the configuration. I have made a brief step by step that will assist anyone with the same problem or those who come across the same.
INSTRUCTIONS
Create a JPA project in new > JPA Project;
Configure the fields Projectile name with the name of your project; the field Target Runtime with the version of his Rhyme; and in the field Configuration choose the option Basic JPA Configuration and click the Next button;
On the JPA Facet screen (two screens after the JPA Project screen) you must:
- Click on Add Connection and configure a connection to your database; after that just click the Finish button;
Ready now your JPA project is already configured and ready to generate its entities. Now just start the resource JPA Tools > Generate Entities from Tables right-clicking on the project. The result is figure below. You select the tables and the tool creates the entities already mapped for you. Amazing resource!
The code below shows the code of the Author entity created from the author table and the relations with this table:
package model;
import java.io.Serializable;
import javax.persistence.*;
import java.util.List;
/**
* The persistent class for the autor database table.
*
*/
@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