As for Netbeans I can’t say, what’s the problem.
But one of the reasons may be that you are accessing the wrong schema.
But to create tables with JPA, you only need to create the
data and JPA with Hibernate for example, is in charge of creating the
tables according to the annotated classes, if using
DDL.
Generating code is never recommended, if it doesn’t work, try creating it manually.
Mapping the classes you want to create and having your CRUD on a DAO.
@Entity
public class Usuario {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "usuarios_seq")
@SequenceGenerator(name = "usuarios_seq", sequenceName = "usuarios_id_seq")
private Long id;
private String nome;
private String email;
private String senha;
//getters e setters
}
Now the DAO class with a CRUD
public class UsuarioDao {
private EntityManager entityManager;
public UsuarioDao() {
entityManager = getEntityManager(); //Ex: Recebe um EntityManager pelo construtor
}
public Usuario usuarioPorId(int id) {
return entityManager.find(Usuario.class, id);
}
public List<Usuario> todosUsuarios() {
return entityManager.createQuery("SELECT u FROM Usuario u", Usuario.class).getResultList();
}
public void gravar(Usuario usuario) {
try {
entityManager.getTransaction().begin();
entityManager.persist(usuario);
entityManager.getTransaction().commit();
} catch (Exception ex) {
ex.printStackTrace();
entityManager.getTransaction().rollback();
}
}
public void atualizar(Usuario usuario) {
try {
entityManager.getTransaction().begin();
entityManager.merge(usuario);
entityManager.getTransaction().commit();
} catch (Exception ex) {
ex.printStackTrace();
entityManager.getTransaction().rollback();
}
}
public void remover(Usuario usuario) {
try {
entityManager.getTransaction().begin();
usuario = entityManager.find(Usuario.class, usuario.getId());
entityManager.remove(usuario);
entityManager.getTransaction().commit();
} catch (Exception ex) {
ex.printStackTrace();
entityManager.getTransaction().rollback();
}
}
}