日期:2014-05-17 浏览次数:20906 次
public List<Employee> find(Employee condition) {
String hql = "from Employee e where 1=1 ";
Object[] values = null;
if(null!=condition){
hql += "and e.sn=? and e.password=?";
values = new Object[]{condition.getSn(),condition.getPassword()};
List<Employee> list = super.getHibernateTemplate().find(hql, values);
for(int i=0;i<list.size();i++){
list.get(i).getPosition();//报错地点
}
return list;
}else{
return super.getHibernateTemplate().find(hql);
}
}
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!-- HibernateTransactionManager bean 需要依赖注入一个 SessionFactory bean的引用 -->
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 定义事务通知,需要指定一个事务管理器 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- 定义属性,声明事务规则 -->
<tx:attributes>
<!-- 对get/find/search/query 开头的方法要求只读事务 -->
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="search*" read-only="true"/>
<tx:method name="query*" read-only="true"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="do*" propagation="REQUIRED"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<aop:config>
<!-- 定义哪些方法应用这些规则 -->
<aop:pointcut id="serviceMethod" expression="execution(* cn.jbit.jboa.service.*.*(..))"/>
<!-- 将事务通知于引用规则的方法组合 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/>
</aop:config>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>