当我输入用户名和密码提交后报错!
这句没通过 List list=studentDaoImpl.getStuByName(name);org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean$TransactionAwareInvocationHandler.invoke(AbstractSessionFactoryBean.java:300)
at $Proxy0.getCurrentSession(Unknown Source)
我有事务声明:
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/demo"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>ssh/model/StudentInfo.hbm.xml</value></list>
</property>
</bean>
<bean id="studentDaoImpl1" class="ssh.dao.impl.StudentDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean name="/login" class="ssh.struts.action.LoginAction" >
<property name="studentDaoImpl">
<ref local="studentDaoImpl1"/>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="studentDaoImpl"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target">
<ref bean="studentDaoImpl1"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>谢谢大家!!
这句没通过 List list=studentDaoImpl.getStuByName(name);org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean$TransactionAwareInvocationHandler.invoke(AbstractSessionFactoryBean.java:300)
at $Proxy0.getCurrentSession(Unknown Source)
我有事务声明:
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/demo"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>ssh/model/StudentInfo.hbm.xml</value></list>
</property>
</bean>
<bean id="studentDaoImpl1" class="ssh.dao.impl.StudentDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean name="/login" class="ssh.struts.action.LoginAction" >
<property name="studentDaoImpl">
<ref local="studentDaoImpl1"/>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="studentDaoImpl"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target">
<ref bean="studentDaoImpl1"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>谢谢大家!!
解决方案 »
- 得到表格数据,生成excel表
- 问个简单的问题..知道的近来下..急!
- ajax读不到返回的xml数据
- 对于ASP中的活的主机IP的方法:Request.ServerVariables("HTTP_X_FORWARDED_FOR"),请问在JSP中有没有对应的方法?
- 出现comp is not bound in this context!
- 关与servlet中dispatcherURL转向的疑问
- 猴急:为什么运行JSP时客户端去掉IE代理才行,否则运行不正常?该如何解决?请大家献计!午饭俺请拉
- 如何在jbuilder7。0中调试一个jsp文件
- 那裏有jsp的源代碼共我學習呀?
- User is not mapped,找不到实体类
- 关于tomact的问题
- JAVA WEB开发 保存文本域编辑文本上传到服务器 并在 当前页面显示文件下载连接
看你的代码应该是用spring管理struts的action
我有点不明白,我在applicationContext.xml声明的是
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
而在我的DAO实现类里面注入的是
import org.hibernate.SessionFactory;
这两个产生的sessionFactory是同一个吗?
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
你这样用 你的实现类就应该是:
public class studentDaoImpl1 implements xxxDAO extends hibernateDaoSupport{
实现xxxDAO中的方法
在方法中需要使用数据库,使用Hibernatetemplate来访问,他的作用和Hibernate中的Session类似
}
Spring和hibernate整合 使用Spring提供的hibernateDaoSupport类 在XML中注入SessionFactory
spring和hibernate整合有两种方式实现DAO
一种是继承HibernateDaoSupport
一种是基于Hibernate3.* 实现Dao
第一种直接由spring提供,由spring管理session ,不用事务
第二种是hibernate自己管理session,由spring注入SessionFactory
同时spring为hibernate提供事务管理 。
第一种我试了 可以实现
现在我想试第二种方式,就是想学一下spring里面事务的使用
现在使用这个方式的时候出错了。
我上面出现了不一样的SessionFactory,我还是不明白该怎么解决