Announcement Announcement Module
No announcement yet.
Why is ConnectionReleaseMode "OnClose" better in spring resource manage enviornment? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why is ConnectionReleaseMode "OnClose" better in spring resource manage enviornment?

    In SpringTransactionFactory, the default release mode is on close. The default is changed to auto since hibernate 3.1, which is AFTER_TRANSACTION for jdbc transaction factory. Can any experts explains why onClose is better than afterTransaction in spring?

    auto (the default) - this choice delegates to the release mode returned by the org.hibernate.transaction.TransactionFactory.getDe faultReleaseMode() method. For JTATransactionFactory, this returns ConnectionReleaseMode.AFTER_STATEMENT; for JDBCTransactionFactory, this returns ConnectionReleaseMode.AFTER_TRANSACTION. It is rarely a good idea to change this default behavior as failures due to the value of this setting tend to indicate bugs and/or invalid assumptions in user code.

     * Spring-aware implementation of the Hibernate TransactionFactory interface, aware of
     * Spring-synchronized transactions (in particular Spring-managed JTA transactions)
     * and asking for default release mode ON_CLOSE. Otherwise identical to Hibernate's
     * default {@link org.hibernate.transaction.JDBCTransactionFactory} implementation.
     * @author Juergen Hoeller
     * @since 2.5.4
     * @see
     * @see org.hibernate.transaction.JDBCTransactionFactory
    public class SpringTransactionFactory implements TransactionFactory {
    	 * Sets connection release mode "on_close" as default.
    	 * <p>This was the case for Hibernate 3.0; Hibernate 3.1 changed
    	 * it to "auto" (i.e. "after_statement" or "after_transaction").
    	 * However, for Spring's resource management (in particular for
    	 * HibernateTransactionManager), "on_close" is the better default.
    	public ConnectionReleaseMode getDefaultReleaseMode() {
    		return ConnectionReleaseMode.ON_CLOSE;
    	public Transaction createTransaction(JDBCContext jdbcContext, Context transactionContext) {
    		return new JDBCTransaction(jdbcContext, transactionContext);
    	public void configure(Properties props) {
    	public boolean isTransactionManagerRequired() {
    		return false;
    	public boolean areCallbacksLocalToHibernateTransactions() {
    		return true;
    	public boolean isTransactionInProgress(
    			JDBCContext jdbcContext, Context transactionContext, Transaction transaction) {
    		return (transaction != null && transaction.isActive()) ||