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.TYPE; 016import static java.lang.annotation.RetentionPolicy.RUNTIME; 017import static javax.persistence.DiscriminatorType.STRING; 018 019/** 020 * Specifies the discriminator column for the <code>SINGLE_TABLE</code> and <code>JOINED</code> 021 * {@link Inheritance} mapping strategies. 022 * <p> 023 * The strategy and the discriminator column are only specified in the root of an entity class hierarchy or 024 * subhierarchy in which a different inheritance strategy is applied 025 * <p> 026 * If the <code>DiscriminatorColumn</code> annotation is missing, and a discriminator column is required, the 027 * name of the discriminator column defaults to <code>"DTYPE"</code> and the discriminator type to 028 * {@link DiscriminatorType#STRING DiscriminatorType.STRING}. 029 * <p> 030 * <pre> 031 * Example: 032 * 033 * @Entity 034 * @Table(name="CUST") 035 * @Inheritance(strategy=SINGLE_TABLE) 036 * @DiscriminatorColumn(name="DISC", discriminatorType=STRING, length=20) 037 * public class Customer { ... } 038 * 039 * @Entity 040 * public class ValuedCustomer extends Customer { ... } 041 * </pre> 042 * 043 * @see DiscriminatorValue 044 * @since Java Persistence 1.0 045 */ 046@Target({TYPE}) 047@Retention(RUNTIME) 048public @interface DiscriminatorColumn { 049 050 /** 051 * (Optional) The name of column to be used for the discriminator. 052 * 053 * @return col name 054 */ 055 String name() default "DTYPE"; 056 057 /** 058 * (Optional) The type of object/column to use as a class discriminator. Defaults to 059 * {@link DiscriminatorType#STRING DiscriminatorType.STRING}. 060 * 061 * @return discrim type 062 */ 063 DiscriminatorType discriminatorType() default STRING; 064 065 /** 066 * (Optional) The SQL fragment that is used when generating the DDL for the discriminator column. 067 * <p> 068 * Defaults to the provider-generated SQL to create a column of the specified discriminator type. 069 * 070 * @return col def 071 */ 072 String columnDefinition() default ""; 073 074 /** 075 * (Optional) The column length for String-based discriminator types. Ignored for other discriminator 076 * types. 077 * 078 * @return length 079 */ 080 int length() default 31; 081}