首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

Spring2.5和hibernate3整合获取全部实例的小疑点

2012-10-13 
Spring2.5和hibernate3整合获取全部实例的小问题本想使用HibernateTemplate类的find(String hql)方法获取

Spring2.5和hibernate3整合获取全部实例的小问题

本想使用HibernateTemplate类的find(String hql)方法获取对应表的所有实例集合。但是遗憾的发现list集合中的bean对象没有主键,其他的值依旧存在,单独使用hibernate没有出现过这种情况。我是用的是spring2.5.6版本的,请问怎么才能是list集合中的bean对象中包含主键,使得与单独使用hibernate获得一样的效果

?


这是Spring的配置文件,应该没问题吧,hibernate的配置文件与单独使用hibernate时的一样。

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns:aop="http://www.springframework.org/schema/aop"      xmlns:tx="http://www.springframework.org/schema/tx"      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">         <!-- 配置hibernate信息-->    <bean id="sessionFactory" value="classpath:hibernate.cfg.xml">    </property>    </bean>                                       <!-- model配置 -->      <bean id="person" depends-on="personService">  <!-- action的成员变量的name必须和引用的bean的id一样,卧槽!!绝对坑爹 -->  <property name="personService">   <ref bean="personService"/>  </property></bean><!-- service配置 --><!----><bean id="baseService" depends-on="baseDao">  <property name="dao">   <ref bean="baseDao" />  </property></bean><bean id="personService" depends-on="personDao">  <property name="dao">   <ref bean="personDao" />  </property></bean><!-- dao配置 --><!----> <bean id="baseDao" />  </property></bean><!-- 事务管理 --><!-- spring管理事物bean,核心类 -->   <bean id="txManager" ref="sessionFactory"/>   </bean>      <!-- 事务管理,相当于切面 ,引用上面的核心类作为插入方法-->   <tx:advice id="txAdvice" transaction-manager="txManager">  <tx:attributes>   <tx:method name="save*" propagation="REQUIRED"/>   <tx:method name="add*" propagation="REQUIRED"/>   <tx:method name="update*" propagation="REQUIRED"/>   <tx:method name="del*" propagation="REQUIRED"/>   <tx:method name="sel*" propagation="REQUIRED"/>  </tx:attributes></tx:advice>   <!-- 动态代理默认返回的是接口类型,所以如果要代理类需要设置 proxy-target-class 属性 --><aop:config proxy-target->  <aop:pointcut id="daoMethods" expression="execution(* com.fzl.ssh.dao..*(..))"/>  <aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods"/></aop:config></beans>

?

这是使用Spring的HibernateTemplate的find方法所得到的结果,没有id<!--StartFragment -->

Spring2.5和hibernate3整合获取全部实例的小疑点

单独使用Hibernate:一切正常,有id,有图有真相

<!--StartFragment -->Spring2.5和hibernate3整合获取全部实例的小疑点<!--StartFragment --><!--StartFragment -->

热点排行