Results 1 to 3 of 3

Thread: hibernate auto flush or custom transaction proxy?

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Location
    China
    Posts
    6

    Default hibernate auto flush or custom transaction proxy?

    i use a custom OpenSessionFilter
    Code:
    public class OpenSessionFilter extends OpenSessionInViewFilter{
        final static Logger logger = Logger.getLogger(OpenSessionFilter.class.getName());
    
        protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
            Session session = SessionFactoryUtils.getSession(sessionFactory, true);
    		return session;
        }
    }
    as what you see, i remove session.setFlushMode(FlushMode.NEVER);
    every thing works fine

    but i see some project ,such as confluence,petclinc sample
    they all use TransactionProxy to do custom transaction on daos like this
    Code:
        <bean id="groupDao" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager">
                <ref local="transactionManager"/>
            </property>
            <property name="target">
                <ref local="confluenceGroupDaoTarget"/>
            </property>
            <property name="transactionAttributes">
                <props>
                    <prop key="*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>
    here is my question:
    what's the different between there two ways
    which is good,and would second way get a poor performace?
    how to choose the apropos way?

    in confluence, some dao seems use way 1 (auto-flush),some use way 2(tran proxy)
    it really confuse me...

  2. #2
    Join Date
    Oct 2004
    Location
    China
    Posts
    6

    Default

    i know

    hibernateTemplate doesnt implement Rollback,it need to be used with TransactionTemplate

    transactionManager did implement rollback operation

    am i right?

  3. #3
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    The OpenSessionInViewFilter is not a replacement for using transactional proxies around your code (or programmatic transactions, which while less convenient than declarative transactions, work effectively the same).

    All the filter does is open the session ahead of time, so when the view layer calls down into the transactionally wrapped service layer, any returned object graphs can still have lazy relationships traversed.

    The default flushmode=never in the filter is appropriate, since what you want is your transaction to flush (it will), and then you don't want to accidentally flush at the end of the request any non-transactional changes that might have been made on the returned data by the view layer.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Similar Threads

  1. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  2. Replies: 0
    Last Post: Jun 6th, 2005, 06:22 AM
  3. Other Hibernate DAO LazyInitializationExceptions
    By bernardsirius in forum Data
    Replies: 5
    Last Post: Feb 18th, 2005, 04:09 PM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 PM

Posting Permissions

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