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.RetentionPolicy.RUNTIME; 017 018/** 019 * Specifies a column that is used to maintain the persistent order of a list. The persistence provider is 020 * responsible for maintaining the order upon retrieval and in the database. The persistence provider is 021 * responsible for updating the ordering upon flushing to the database to reflect any insertion, deletion, or 022 * reordering affecting the list. 023 * <p> 024 * The <code>OrderColumn</code> annotation is specified on a OneToMany or ManyToMany relationship or on an 025 * element collection. The <code>OrderColumn</code> annotation is specified on the side of the relationship 026 * that references the collection that is to be ordered. The order column is not visible as part of the state 027 * of the entity or embeddable class. 028 * <p> 029 * The {@link OrderBy} annotation should be used for ordering that is visible as persistent state and 030 * maintained by the application. The <code>OrderBy</code> annotation is not used when 031 * <code>OrderColumn</code> is specified. 032 * <p> 033 * The order column must be of integral type. The persistence provider maintains a contiguous (non-sparse) 034 * ordering of the values of the order column when updating the association or element collection. The order 035 * column value for the first element is 0. 036 * <p> 037 * <pre> 038 * 039 * Example: 040 * 041 * @Entity 042 * public class CreditCard { 043 * 044 * @Id long ccNumber; 045 * 046 * @OneToMany // unidirectional 047 * @OrderColumn 048 * List<CardTransaction> transactionHistory; 049 * ... 050 * } 051 * 052 * </pre> 053 * 054 * @see OrderBy 055 * @since Java Persistence 2.0 056 */ 057@Target({FIELD}) 058@Retention(RUNTIME) 059public @interface OrderColumn { 060 061 /** 062 * (Optional) The name of the ordering column. Defaults to the concatenation of the name of the 063 * referencing property or field; "_"; "ORDER". 064 * 065 * @return name 066 */ 067 String name() default ""; 068 069 /** 070 * (Optional) Whether the database column is nullable. 071 * 072 * @return whether nullable 073 */ 074 boolean nullable() default true; 075 076 /** 077 * (Optional) Whether the column is included in SQL INSERT statements generated by the persistence 078 * provider. 079 * 080 * @return whether insertable 081 */ 082 boolean insertable() default true; 083 084 /** 085 * (Optional) Whether the column is included in SQL UPDATE statements generated by the persistence 086 * provider. 087 * 088 * @return whether updateable 089 */ 090 boolean updatable() default true; 091 092 /** 093 * (Optional) The SQL fragment that is used when generating the DDL for the column. Defaults to generated 094 * SQL to create a column of the inferred type. 095 * 096 * @return column definition 097 */ 098 String columnDefinition() default ""; 099}