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 a container-managed {@link EntityManager} and its 021 * associated persistence context. 022 * 023 * @since Java Persistence 1.0 024 */ 025@Target({TYPE, METHOD, FIELD}) 026@Retention(RUNTIME) 027@Repeatable(PersistenceContexts.class) 028public @interface PersistenceContext { 029 030 /** 031 * (Optional) The name by which the entity manager is to be accessed in the 032 * environment referencing context; not needed when dependency 033 * injection is used. 034 * 035 * @return Name 036 */ 037 String name() default ""; 038 039 /** 040 * (Optional) The name of the persistence unit as defined in the 041 * <code>persistence.xml</code> file. If the <code>unitName</code> element is 042 * specified, the persistence unit for the entity manager that is 043 * accessible in JNDI must have the same name. 044 * 045 * @return unit name 046 */ 047 String unitName() default ""; 048 049 /** 050 * (Optional) Specifies whether a transaction-scoped persistence context 051 * or an extended persistence context is to be used. 052 * 053 * @return type 054 */ 055 PersistenceContextType type() default PersistenceContextType.TRANSACTION; 056 057 /** 058 * (Optional) Specifies whether the persistence context is always automatically synchronized with the current 059 * JTA transaction or whether the persistence context must be explicitly joined to the current JTA transaction by 060 * means of the EntityManager joinTransaction method 061 * 062 * @return sync 063 * @since Java Persistence 2.1 064 */ 065 SynchronizationType synchronization() default SynchronizationType.SYNCHRONIZED; 066 067 /** 068 * (Optional) Properties for the container or persistence 069 * provider. Vendor specific properties may be included in this 070 * set of properties. Properties that are not recognized by 071 * a vendor are ignored. 072 * 073 * @return properties 074 */ 075 PersistenceProperty[] properties() default {}; 076}