只需在配置文件ApplicationContext.xml中加入下面代码红色部分。
<bean id="sessionFactory"
         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
         destroy-method="destroy" >
         <property name="dataSource" ref="dataSource" />
         <property name="mappingResources">
           <list>
             <value>com/snsoft/crm/domain/SnRukudan.hbm.xml</value>
             <value>com/snsoft/crm/domain/SnKehu.hbm.xml</value
         </list>
         </property>
         <property name="hibernateProperties">
           <props>
             <prop key="hibernate.query.factory_class">
                 org.hibernate.hql.classic.ClassicQueryTranslatorFactory
             </prop> 
             <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
             <prop key="hibernate.show_sql">false</prop>
           </props>
         </property>         
   </bean> 
上面这种方法有时也会存在很多问题,最好的方法还是利用Hiberante的参数绑定。例如:
 Query query = session.createQuery("from TUser user where user.name=? and user,age>?");
Query query = session.createQuery("from TUser user where user.name=? and user,age>?");
 query.setString(0,"Erica");
query.setString(0,"Erica");
 query.setInteger(1,20);
query.setInteger(1,20);posted on 2009-04-18 00:29 
龙华城 阅读(1858) 
评论(1)  编辑  收藏  所属分类: 
Hibernate