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
012import java.lang.annotation.Retention;
013import java.lang.annotation.Target;
014
015import static java.lang.annotation.ElementType.FIELD;
016import static java.lang.annotation.ElementType.METHOD;
017import static java.lang.annotation.RetentionPolicy.RUNTIME;
018
019/**
020 * Specifies the version field or property of an entity class that
021 * serves as its optimistic lock value.  The version is used to ensure
022 * integrity when performing the merge operation and for optimistic
023 * concurrency control.
024 * <p>
025 * <p> Only a single <code>Version</code> property or field
026 * should be used per class; applications that use more than one
027 * <code>Version</code> property or field will not be portable.
028 * <p>
029 * <p> The <code>Version</code> property should be mapped to
030 * the primary table for the entity class; applications that
031 * map the <code>Version</code> property to a table other than
032 * the primary table will not be portable.
033 * <p>
034 * <p> The following types are supported for version properties:
035 * <code>int</code>, <code>Integer</code>, <code>short</code>,
036 * <code>Short</code>, <code>long</code>, <code>Long</code>,
037 * <code>java.sql.Timestamp</code>.
038 * <p>
039 * <pre>
040 *    Example:
041 *
042 *    &#064;Version
043 *    &#064;Column(name="OPTLOCK")
044 *    protected int getVersionNum() { return versionNum; }
045 * </pre>
046 *
047 * @since Java Persistence 1.0
048 */
049@Target({METHOD, FIELD})
050@Retention(RUNTIME)
051public @interface Version {
052}