开发者

opensessioninview and commit transaction

I am using Hibernate, Spring and JSF.

In order to prevent LazyInitializationException I am using

<bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
        <property name="sessionFactory" ref="sessionFactory"/>
        <property name="singleSession" value="true"/>
</bean>

In myDAO, I defined the method:

public Collection<T> findAll() {
        Session session = getSessionFactory().getCurrentSession();
        Transaction tx = session.beginTransaction();
        return 
            session.createCriteria( persistentClass 
                    ).setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY
                            ).list();
    }

and I call the method like this:

@Transactional( readOnly = false, propagation = Propagation.SUPPORTS )
  开发者_如何学运维  public Collection<MyData> getMyData() {
        return (Collection<MyData>) myDAO.findAll();
    }

In this case I used Spring transaction. Do I need the start the transaction in Transaction tx = session.beginTransaction(); and tx.commit()? in findAll method?

I am using Oracle 10g


When using @Transactional (and you have a bean called transactionManager, and have <tx:annotation-driven />), then you don't need to manually handle transactions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜