当前位置: 代码迷 >> Java Web开发 >> ~ spring3.1+hibernate4.1.4 无法正常使用session
  详细解决方案

~ spring3.1+hibernate4.1.4 无法正常使用session

热度:821   发布时间:2016-04-12 22:07:05.0
求助~ spring3.1+hibernate4.1.4 无法正常使用session
配置:
applicationContext

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="xxtz_sys"></property>
<property name="password" value="xxtz_sys"></property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle10gDialect
</prop>
<prop key="hibernate.max_fetch_depth">1</prop>
<prop key="show_sql">true</prop>
</props>
</property>
</bean>


DAO:

private SessionFactory sessionFactory;
private Session session;

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
protected Session getSession(){
return sessionFactory.getCurrentSession();
}

public List<Cls> findByPage(final String hql, final Page page)
throws Exception {
List<Cls> list = new ArrayList<Cls>();
session = getSession();
Query query = session.createQuery(hql);
query.setFirstResult(page.getStartrow());
query.setMaxResults(page.getRowsperpage());
list = query.list();
return list;
}


异常:
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is java.lang.UnsupportedOperationException: The application must supply JDBC connections
at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:440)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
  相关解决方案