class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
org.hibernate.dialect.OracleDialect true true
cn/bdqn/jboa/entity/CheckResult.hbm.xml cn/bdqn/jboa/entity/ClaimVoucher.hbm.xml cn/bdqn/jboa/entity/ClaimVoucherDetail.hbm.xml cn/bdqn/jboa/entity/Department.hbm.xml cn/bdqn/jboa/entity/Dictionary.hbm.xml cn/bdqn/jboa/entity/Employee.hbm.xml cn/bdqn/jboa/entity/Position.hbm.xml
hibernate中的hibernate.cfg.xml
2 56 7 8 29 309 jdbc:oracle:thin:@localhost:1521:jbit10 11rong 12rong 1314 oracle.jdbc.driver.OracleDriver15 1617 org.hibernate.dialect.OracleDialect18 19true 20true 2122 23 24 25 26 27 28
更改后,调用事务就变得很简单了
1 public class UserDaoImpl extends HibernateDaoSupport implements UserDao{2 3 @Override4 public Employee findById(Serializable id) {5 // TODO Auto-generated method stub6 return this.getHibernateTemplate().get(Employee.class, id);7 }8 9 }
创建接口类
1 public interface ClaimVoucherDao {2 public Listfind(int first,int pageSize);3 }
回调机制
1 /** 2 * 报销单类 3 * @author Administrator 4 * 5 */ 6 public class ClaimVoucherDaoImpl extends HibernateDaoSupport implements ClaimVoucherDao{ 7 8 @SuppressWarnings("unchecked") 9 @Override10 public Listfind(final int first, final int pageSize) {11 12 13 return this.getHibernateTemplate().executeFind(new HibernateCallback() {14 15 @Override16 public Object doInHibernate(Session arg0)17 throws HibernateException, SQLException {18 // TODO Auto-generated method stub19 return arg0.createQuery(" from ClaimVoucher c")20 .setFirstResult(first)21 .setMaxResults(pageSize)22 .list();23 }24 });25 }26 }
在xml中添加dao的实例
1 23 54 6 7
测试类
public class testClaim { @Test public void test() { ApplicationContext ctx = new ClassPathXmlApplicationContext( "applicationContext.xml"); ClaimVoucherDao claimVoucherDao = (ClaimVoucherDao) ctx.getBean("claimVoucherDao"); System.out.println(claimVoucherDao.find(0, 3)); System.out.println(claimVoucherDao.find(4, 3)); }}