001package io.ebean;
002
003/**
004 * Defines the scope for PersistenceContext.
005 * <p/>
006 * Ebean has traditionally used Transaction scope for the PersistenceContext. This is used to change the scope to
007 * use (by default) and explicitly set the scope to use for an individual query.
008 *
009 * @see io.ebean.config.DatabaseConfig#setPersistenceContextScope(PersistenceContextScope)
010 * @see Query#setPersistenceContextScope(PersistenceContextScope)
011 */
012public enum PersistenceContextScope {
013
014  /**
015   * PersistenceContext is scoped to the transaction.
016   * <p/>
017   * If a transaction spans 2 or more queries that fetch the same bean in terms of same type
018   * and same Id value then they share the same bean instance.
019   * <p/>
020   * You may want to change to use QUERY scope when you want a query executing in a transaction to effectively
021   * ignore beans that have already been loaded (by other queries in the same transaction) and instead get a
022   * 'fresh copy' of the bean.
023   */
024  TRANSACTION,
025
026  /**
027   * PersistenceContext is scoped to the query.
028   * <p/>
029   * This means that for this query running in an existing transaction then it will effectively ignore any beans
030   * that have already been queried/loaded by prior queries in the same transaction.
031   * <p/>
032   * You may use QUERY scope on a query that is executed in a transaction and you want to get a 'fresh copy' of the bean.
033   */
034  QUERY
035}