001/*
002 * Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved.
003 *
004 * This program and the accompanying materials are made available under the
005 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
006 * which accompanies this distribution.  The Eclipse Public License is available
007 * at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License
008 * is available at http://www.eclipse.org/org/documents/edl-v10.php.
009 */
010package javax.persistence;
011
012
013/**
014 * Thrown by the persistence provider when an optimistic locking conflict
015 * occurs. This exception may be thrown as part of an API call, a flush or at
016 * commit time. The current transaction, if one is active, will be marked for
017 * rollback.
018 *
019 * @see EntityManager#find(Class, Object, LockModeType)
020 * @see EntityManager#find(Class, Object, LockModeType, java.util.Map)
021 * @see EntityManager#lock(Object, LockModeType)
022 * @see EntityManager#lock(Object, LockModeType, java.util.Map)
023 * @since Java Persistence 1.0
024 */
025public class OptimisticLockException extends PersistenceException {
026
027  /**
028   * The object that caused the exception
029   */
030  Object entity;
031
032  /**
033   * Constructs a new <code>OptimisticLockException</code> exception with
034   * <code>null</code> as its detail message.
035   */
036  public OptimisticLockException() {
037    super();
038  }
039
040  /**
041   * Constructs a new <code>OptimisticLockException</code> exception with the
042   * specified detail message.
043   *
044   * @param message the detail message.
045   */
046  public OptimisticLockException(String message) {
047    super(message);
048  }
049
050  /**
051   * Constructs a new <code>OptimisticLockException</code> exception with the
052   * specified detail message and cause.
053   *
054   * @param message the detail message.
055   * @param cause   the cause.
056   */
057  public OptimisticLockException(String message, Throwable cause) {
058    super(message, cause);
059  }
060
061  /**
062   * Constructs a new <code>OptimisticLockException</code> exception with the
063   * specified cause.
064   *
065   * @param cause the cause.
066   */
067  public OptimisticLockException(Throwable cause) {
068    super(cause);
069  }
070
071  /**
072   * Constructs a new <code>OptimisticLockException</code> exception with the
073   * specified entity.
074   *
075   * @param entity the entity.
076   */
077  public OptimisticLockException(Object entity) {
078    this.entity = entity;
079  }
080
081  /**
082   * Constructs a new <code>OptimisticLockException</code> exception with the
083   * specified detail message, cause, and entity.
084   *
085   * @param message the detail message.
086   * @param cause   the cause.
087   * @param entity  the entity.
088   */
089  public OptimisticLockException(String message, Throwable cause, Object entity) {
090    super(message, cause);
091    this.entity = entity;
092  }
093
094  /**
095   * Returns the entity that caused this exception.
096   *
097   * @return the entity.
098   */
099  public Object getEntity() {
100    return this.entity;
101  }
102
103}