Results 1 to 2 of 2

Thread: hibernate configration with Open view session filter

  1. #1

    Default hibernate configration with Open view session filter

    I have extended sessionfilter which sets the flush mode to auto in getSession() method and in close session method closes if session is not closed it calls flush and finally closes , I also use Spring @Transaction annotation, First I am confused with the hibernate property

    hibernate.current_session_context_class what should be the value of this and how this will effect my setup ,

    and why am i doting this
    Code:
    <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
    and this ?
    Code:
        <bean id="transactionManager"
    		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    	<property name="sessionFactory" ref="sessionFactory" />
        </bean>

    and finally how will this help me ?

    Code:
    <prop key="hibernate.connection.release_mode">auto</prop>
    Code:
    public class HibernateFilter extends OpenSessionInViewFilter {
    	
    	@Override
    	public void setSingleSession(boolean singleSession) {
    		// TODO Auto-generated method stub
    		super.setSingleSession(false);
    	}
    	
    	@Override
    	protected Session getSession(SessionFactory sessionFactory)
    			throws DataAccessResourceFailureException {
    		
    		
    		
    		Session session = SessionFactoryUtils.getSession(sessionFactory, true);
    
    		// set the FlushMode to auto in order to save objects.
    
    		session.setFlushMode(FlushMode.AUTO);
    
    		return session;
    
    	}
    
    	@Override
    	protected void closeSession(Session session, SessionFactory sessionFactory) {
    
    	
    		try {
    
    			if (session != null && session.isOpen() && session.isConnected()) {
    
    				try {
    					session.flush();
    				}
    
    				catch (HibernateException e) {
    					throw new CleanupFailureDataAccessException(
    							"Failed to flush session before close: "
    									+ e.getMessage(), e);
    				}
    
    				catch (Exception e) {
    				}
    			}
    		}
    
    		finally {
    			super.closeSession(session, sessionFactory);
    		}
    	}
    }

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Just wondering why? Flushing occurs automatically because it is handled from withing the transaction which is started with spring.

    the 'hibernate.current_session_context_class' shouldn't be set only if you use JTA and judging from your configuration you don't. The same goes for the 'hibernate.transaction.factory_class' key it shouldn't be set either.

    I still don't get what you are trying to achieve with your own OSIVF....
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •