Example usage for javax.persistence OptimisticLockException OptimisticLockException

List of usage examples for javax.persistence OptimisticLockException OptimisticLockException

Introduction

In this page you can find the example usage for javax.persistence OptimisticLockException OptimisticLockException.

Prototype

public OptimisticLockException(String message, Throwable cause, Object entity) 

Source Link

Document

Constructs a new OptimisticLockException exception with the specified detail message, cause, and entity.

Usage

From source file:de.micromata.genome.jpa.Emgr.java

@Override
public void deleteDetached(DbRecord<?> rec, boolean overwrite) throws OptimisticLockException {
    DbRecord<?> dbrec = selectByPkAttached(rec.getClass(), rec.getPk());
    if (overwrite == false && rec instanceof StdRecord && dbrec instanceof StdRecord) {
        Integer thisupc = ((StdRecord<?>) rec).getUpdateCounter();
        Integer dbupc = ((StdRecord<?>) dbrec).getUpdateCounter();
        if (Objects.equals(thisupc, dbupc) == false) {
            throw new OptimisticLockException("Cannot delete " + dbrec.getClass().getName() + "("
                    + dbrec.getPk() + ") because version conflict: " + " old updatecounter: " + thisupc
                    + "; new updatecounter: " + dbupc, null, dbrec);
        }/*  w  w w .  j ava  2s .  c  o  m*/
    }
    deleteAttached(dbrec);
}