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; 017 018/** 019 * Specifies that a unique constraint is to be included in 020 * the generated DDL for a primary or secondary table. 021 * <p> 022 * <pre> 023 * Example: 024 * @Entity 025 * @Table( 026 * name="EMPLOYEE", 027 * uniqueConstraints= 028 * @UniqueConstraint(columnNames={"EMP_ID", "EMP_NAME"}) 029 * ) 030 * public class Employee { ... } 031 * </pre> 032 * 033 * @since Java Persistence 1.0 034 */ 035@Target({TYPE}) 036@Retention(RUNTIME) 037public @interface UniqueConstraint { 038 /** 039 * (Optional) Constraint name. A provider-chosen name will be chosen 040 * if a name is not specified. 041 * 042 * @return name 043 * @since Java Persistence 2.0 044 */ 045 String name() default ""; 046 047 /** 048 * (Required) An array of the column names that make up the constraint. 049 * 050 * @return col names 051 */ 052 String[] columnNames(); 053}