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 * Thrown by the persistence provider when an pessimistic locking conflict 014 * occurs. This exception may be thrown as part of an API call, a flush or at 015 * commit time. The current transaction, if one is active, will be marked for 016 * rollback. 017 * 018 * @since Java Persistence 2.0 019 */ 020public class PessimisticLockException extends PersistenceException { 021 /** 022 * The object that caused the exception 023 */ 024 Object entity; 025 026 /** 027 * Constructs a new <code>PessimisticLockException</code> exception 028 * with <code>null</code> as its detail message. 029 */ 030 public PessimisticLockException() { 031 super(); 032 } 033 034 /** 035 * Constructs a new <code>PessimisticLockException</code> exception 036 * with the specified detail message. 037 * 038 * @param message the detail message. 039 */ 040 public PessimisticLockException(String message) { 041 super(message); 042 } 043 044 /** 045 * Constructs a new <code>PessimisticLockException</code> exception 046 * with the specified detail message and cause. 047 * 048 * @param message the detail message. 049 * @param cause the cause. 050 */ 051 public PessimisticLockException(String message, Throwable cause) { 052 super(message, cause); 053 } 054 055 /** 056 * Constructs a new <code>PessimisticLockException</code> exception 057 * with the specified cause. 058 * 059 * @param cause the cause. 060 */ 061 public PessimisticLockException(Throwable cause) { 062 super(cause); 063 } 064 065 /** 066 * Constructs a new <code>PessimisticLockException</code> exception 067 * with the specified entity. 068 * 069 * @param entity the entity. 070 */ 071 public PessimisticLockException(Object entity) { 072 this.entity = entity; 073 } 074 075 /** 076 * Constructs a new <code>PessimisticLockException</code> exception 077 * with the specified detail message, cause, and entity. 078 * 079 * @param message the detail message. 080 * @param cause the cause. 081 * @param entity the entity. 082 */ 083 public PessimisticLockException(String message, Throwable cause, Object entity) { 084 super(message, cause); 085 this.entity = entity; 086 } 087 088 /** 089 * Returns the entity that caused this exception. 090 * 091 * @return the entity. 092 */ 093 public Object getEntity() { 094 return this.entity; 095 } 096}