I have a problem with JPA with Java.
I made a login system, using a self-generated ID, but every time I run the program it creates another user in the database, with a different id but same credentials.
How do I, if this user login already exists, does not create an equal one?
Method that starts with the application:
public void startApp() {
service = new Service<List<Usuario>>() {
@Override
protected Task<List<Usuario>> createTask() {
return new Task<List<Usuario>>() {
@Override
protected List<Usuario> call() throws Exception {
Usuario user = new Usuario();
user.setNome("Usuario");
user.setLogin("user");
user.setSenha("123");
UsuarioDAO usuarioDAO = new UsuarioDAO();
usuarioDAO.inserir(user);
return usuarioDAO.obterLista();
}
};
}
};
JPA Insert Method
public boolean inserir(Usuario usuario) {
try {
entidadeGerenciamento.getTransaction().begin();
entidadeGerenciamento.persist(usuario);
entidadeGerenciamento.getTransaction().commit();
return true;