As for Netbeans, I do not know what the problem is.
But one of the reasons may be that you are accessing the wrong schema.
But to create tables with JPA, you just need to create the database
data and JPA with Hibernate for example, is responsible for creating the
tables according to the annotated classes, if you are using
DDL.
Generating code is never recommended, if it does not work, try to create it manually.
Mapping the classes you want to create and taking your CRUD into 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();
}
}
}