Autoincrement error in jpa


This message I get when you perform the insert in the database and it does not give any errors, it only gives this message of warning .


Warning: The class RepeatableWriteUnitOfWork is already flushing. The query will be executed without further changes being written to the database. If the query is conditional upon changed data the changes may not be reflected in the results. Users should issue a flush () call upon completion of the dependent changes and prior to this flush () to ensure correct results.

    NclDocumento documento = null;
    try {
        NclTipoDocumento tipo = findTipoDocumentoById(tipoD.getValue());
        if (numero != null && numero != 0 && anioSelected != null) {
            documento = findAcuerdoByNumeroAndAnioAndTipoDocumento(numero, anioSelected, tipo);

            if (documento != null) {
                return new Response<>(documento, ResponseStatus.OK_INSERT);


        if (documento == null) {
            documento = new NclDocumento();
            documento.setFechaEmision(new Date());
           if (firma != null && firma.getEmpleado() != null) {
            documento.setFechaCreacion(new Date());

        return new Response<>(documento, ResponseStatus.OK_INSERT);
    } catch (ConstraintViolationException ex) {
        String validationError = getConstraintViolationExceptionAsString(ex);
        return new Response<>(ResponseStatus.ERROR_PARAMS, "Sucedio un error con la información: " + validationError);
    } catch (Exception ex) {
        return new Response<>(ResponseStatus.ERROR, "Sucedio un error: " + ex.getMessage());
asked by Raul Cacacho 11.12.2017 в 22:45

1 answer


What you are doing em.flush(); is doing what would come to be an "immediate execution" of em.persist(documento); . The correct use of the flush() is when you want to perform the execution of the sql instructions that are waiting for the commit to execute some others that may depend on them, such as bringing the autoincrementable id of em.persist(documento); to perform other operations with the entityManager.

The warning tells you that you are forcing a flush() when one is already in progress (as is normal when committing). Look at it as if you were doing a double commit at the end and the implementer is telling you: "You are sending a commit that is not having an effect because it is next to another: Are you sure you should not go before?"

It is not an error, but a warning that something is happening to you. Maybe you have autocommit and the flush should not go.

answered by 11.12.2017 / 23:36