1
I have a JPA problem with Java.
I built 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 so that if there is already this user login, it does not create another equal?
Method that starts along 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();
}
};
}
};
Insert Method from JPA
public boolean inserir(Usuario usuario) {
try {
entidadeGerenciamento.getTransaction().begin();
entidadeGerenciamento.persist(usuario);
entidadeGerenciamento.getTransaction().commit();
return true;