How to disable "update" in the "save" method of JpaRepository

0

I'm trying to insert a new user into my user table and I want to have control if we insert an existing user that does not update it.

Currently it seems that the save method or saveFlush derivatives try to insert and if they already exist they update. To avoid this I could run the method findByid and then save or throw the exception but I would like to avoid that

My current code would be like this but never enters by the exception

   try {
        usuario = usuariosDao.saveAndFlush(usuario)
    } catch (e: org.springframework.dao.DataIntegrityViolationException) {
        throw MySqlException(HttpStatus.CONFLICT, MySqlException.EX_SQL_RQ_USER_ALREDY_REGISTER, MySqlException.EX_SQL_MSG_USER_ALREDY_REGISTER)
    }
    
asked by Rulogarcillan 17.12.2018 в 16:49
source

0 answers