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