锁定老帖子 主题:讨论:在DAO中对Hibernate的封装
该帖已经被评为精华帖
|
|
---|---|
作者 | 正文 |
发表时间:2004-09-03
为啥不用Spring+Hibernate 那?
只要在DAO操作如下就可以了: import org.springframework.orm.hibernate.support.HibernateDaoSupport; public class ReportingHibernateDAO extends HibernateDaoSupport implements IReportingDAO { /** * */ public ReportingHibernateDAO(); { super();; // TODO Auto-generated constructor stub } /** * * @return List */ public List getAngetCountbyRoot(); throws Exception { List angetcount = new ArrayList();; String hql = "select agent.id from Agent as agent where agent.uaid is NULL"; try { angetcount = getHibernateTemplate();.find(hql);; } catch (Exception e); { // TODO Auto-generated catch block e.printStackTrace();; } return angetcount; } } 因为Spring已经支持了Hibernate的DAO操作,把事务都封装在了配置文件中: <bean id="iReportingService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"><ref local="myTransactionManager"/></property> <property name="target"><ref local="iReportingTarget"/></property> <property name="transactionAttributes"> <props> <prop key="getReporting*">PROPAGATION_REQUIRED,readOnly,-OfficeException</prop> <prop key="save*">PROPAGATION_REQUIRED,-OfficeException</prop> <prop key="edit*">PROPAGATION_REQUIRED,-OfficeException</prop> <prop key="del*">PROPAGATION_REQUIRED,-OfficeException</prop> <prop key="getAllReporting">PROPAGATION_REQUIRED,-OfficeException</prop> </props> </property> </bean> <!-- ADD iReportingTarget primary business object implementation --> <bean id="iReportingTarget" class="com.uplus.service.spring.ReportingServiceSpringImpl"> <property name="reportingDAO"><ref local="reportingDAO"/></property> </bean> <!-- DAO object: Hibernate implementation --> <bean id="reportingDAO" class="com.uplus.service.dao.hibernate.ReportingHibernateDAO"> <property name="sessionFactory"><ref local="mySessionFactory"/></property> </bean> |
|
返回顶楼 | |
发表时间:2004-09-07
Good!Thanks for sharing!:)
|
|
返回顶楼 | |
发表时间:2006-12-25
|
|
返回顶楼 | |