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.Repeatable; 013import java.lang.annotation.Retention; 014import java.lang.annotation.Target; 015 016import static java.lang.annotation.ElementType.*; 017import static java.lang.annotation.RetentionPolicy.RUNTIME; 018 019/** 020 * Expresses a dependency on an {@link EntityManagerFactory} and its 021 * associated persistence unit. 022 * 023 * @since Java Persistence 1.0 024 */ 025@Target({TYPE, METHOD, FIELD}) 026@Retention(RUNTIME) 027@Repeatable(PersistenceUnits.class) 028public @interface PersistenceUnit { 029 /** 030 * (Optional) The name by which the entity manager factory is to be accessed 031 * in the environment referencing context; not needed when 032 * dependency injection is used. 033 * 034 * @return name 035 */ 036 String name() default ""; 037 038 /** 039 * (Optional) The name of the persistence unit as defined in the 040 * <code>persistence.xml</code> file. If specified, the 041 * persistence unit for the entity manager factory that is 042 * accessible in JNDI must have the same name. 043 * 044 * @return unit name 045 */ 046 String unitName() default ""; 047}