我的spring的配置文件:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" destroy-method="close">
<property name="location">
<value>classpath:sqlresource.properties</value>
</property>
</bean>



<!--  
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUrl" value="${database.url}" />
        <property name="user" value="${database.username}" />
        <property name="password" value="${database.password}" />
        <property name="autoCommitOnClose" value="false"/>
        <property name="checkoutTimeout" value="5000"/>
        <property name="initialPoolSize" value="5"/>
        <property name="minPoolSize" value="5"/>
        <property name="maxPoolSize" value="40"/>
        <property name="maxIdleTime" value="60"/>
        <property name="acquireIncrement" value="5"/>
        <property name="idleConnectionTestPeriod" value="60"  />
        <property name="testConnectionOnCheckin" value="true" />
        <property name="testConnectionOnCheckout" value="true"/>
        <property name="maxIdleTimeExcessConnections" value="1800"/>
         <property name="preferredTestQuery" value="select * from userinfo"/>
 </bean>
-->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
 abstract= "false " singleton= "true "   
lazy-init= "default "   autowire= "default " 
       dependency-check= "default ">
<property name="driverClassName">
<value>${database.driverclassname}</value>
</property>
<property name="url">
<value>${database.url}</value>
</property>
<property name="username">
<value>${database.username}</value>
</property>
<property name="password">
<value>${database.password}</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>
cn/bozhong/apps/iptv/domain/Propinfo.hbm.xml
</value>
<value>cn/bozhong/apps/iptv/domain/Userfriend.hbm.xml</value>
<value>
cn/bozhong/apps/iptv/domain/Styleinfo.hbm.xml
</value>
<value>
cn/bozhong/apps/iptv/domain/Userprop.hbm.xml
</value>
<value>
cn/bozhong/apps/iptv/domain/Userinfo.hbm.xml
</value>
<value>cn/bozhong/apps/iptv/domain/Gameinfo.hbm.xml</value>
<value>cn/bozhong/apps/iptv/domain/Userstyle.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean> <bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean> <bean id="baseTxProxy" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property> <property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="select*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- Propinfo -->
<bean id="propinfoDao"
class="cn.bozhong.apps.iptv.service.dao.hibernate.PropinfoDao"
autowire="byName">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="propinfoService"
class="cn.bozhong.apps.iptv.service.spring.PropinfoService"
singleton="true" autowire="byName">
<property name="dao">
<ref local="propinfoDao" />
</property>
</bean>
<bean id="propinfoServiceProxy" parent="baseTxProxy">
<property name="target">
<ref local="propinfoService" />
</property>
</bean>
</beans>

解决方案 »

  1.   

    我的分页的代码如下:
     public List getList(final   String   hql,   final   int   pageNo,   final   int   pageSize) { 
     return this.getHibernateTemplate().executeFind(new HibernateCallback(){ 
     public Object doInHibernate(Session session) throws HibernateException, SQLException { 
     Query query=session.createQuery(hql); 
     query.setFirstResult((pageNo-1)*pageSize); //hibernate分页的精髓 呵呵 
     query.setMaxResults(pageSize); 
     session.close();
     return query.list(); 
     } 
     }); 
     } 
      

  2.   

    org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection
    数据库的连接问题
    你的操作后,数据库连接没关。
    public List getList(final   String   hql,   final   int   pageNo,   final   int   pageSize) { 
     return this.getHibernateTemplate().executeFind(new HibernateCallback(){ 
     public Object doInHibernate(Session session) throws HibernateException, SQLException { 
     Query query=session.createQuery(hql); 
     query.setFirstResult((pageNo-1)*pageSize); //hibernate分页的精髓 呵呵 
     query.setMaxResults(pageSize); 
     session.close();
     return query.list(); 
     } 
     }); 
     } 
      

  3.   

    session.close()这个不是关闭数据库的连接吗,,还有其他的方法关闭吗?
      

  4.   

    我也碰到了改问题,在网上查了下,有人说是用的mysql数据库,不支持事务,不晓得怎解决,在线关注。