    001// Copyright 2007, 2008 The Apache Software Foundation
    002//
    003// Licensed under the Apache License, Version 2.0 (the "License");
    004// you may not use this file except in compliance with the License.
    005// You may obtain a copy of the License at
    006//
    007//     http://www.apache.org/licenses/LICENSE-2.0
    008//
    009// Unless required by applicable law or agreed to in writing, software
    010// distributed under the License is distributed on an "AS IS" BASIS,
    011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012// See the License for the specific language governing permissions and
    013// limitations under the License.
    014
    015package org.apache.tapestry5.hibernate;
    016
    017import org.hibernate.Session;
    018
    019/**
    020 * Manages the Hibernate session for the current thread. This includes creating the session as needed, allowing the
    021 * session to checkpoint (commit the current transaction and continue) and commit the transaction automatically at the
    022 * end of the request.
    023 * <p/>
    024 * Remember that in Tapestry, action requests and render requests are entirely separate, and you will see a separate
    025 * request and a separate transaction for each. Care should be taken to ensure that entity objects that are retained (in
    026 * the session, as persistent field values) between requests are handled correctly (they tend to become detached
    027 * instances).
    028 * <p/>
    029 * This implementation of this service is per-thread.
    030 */
    031public interface HibernateSessionManager
    032{
    033    /**
    034     * Gets the active session for this request, creating it as necessary. When the session is first created, a
    035     * transaction is started.
    036     *
    037     * @return the request's session
    038     * @see HibernateSessionSource
    039     */
    040    Session getSession();
    041
    042    /**
    043     * Commits the current transaction (which will cause a flush of data to the database), then starts a new transaction
    044     * to replace it.
    045     */
    046    void commit();
    047
    048    /**
    049     * Aborts the current transaction, and starts a new transaction to replace it.
    050     */
    051    void abort();
    052}