2006-10-27
spring+hibernate之applicationContext.xml配置
关键字: spring hibernate
最近一段时间潜心自学struts,spring,hibernate框架,写了一些独立框架的例子还算顺利,今天试着将spring与hibernate整合,遇到一些问题,故写此文。
主要功能:完成数据库表的查、增、删、改操作。
问题描述:查询功能一切正常,但是在增、删、改操作中发现,数据库表中数据没有改变,查看控制台日志也没有任何异常发现,纳闷了好久,仔查检查日志,发现在新增操作中表id有在自增,由此确定是问题出在事务没有提交。将事务配置上去后出现如下报错:java.lang.ClassCastException: $Proxy1,百度上搜到一文,在业务类如果实现了接口,得增加如下代码
<property name="proxyTargetClass">
<value>true</value>
</property>
果然如此,再次运行,成功了!
以下是我applicationContext.xml的内容:
主要功能:完成数据库表的查、增、删、改操作。
问题描述:查询功能一切正常,但是在增、删、改操作中发现,数据库表中数据没有改变,查看控制台日志也没有任何异常发现,纳闷了好久,仔查检查日志,发现在新增操作中表id有在自增,由此确定是问题出在事务没有提交。将事务配置上去后出现如下报错:java.lang.ClassCastException: $Proxy1,百度上搜到一文,在业务类如果实现了接口,得增加如下代码
<property name="proxyTargetClass">
<value>true</value>
</property>
果然如此,再次运行,成功了!
以下是我applicationContext.xml的内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="myTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="mySessionFactory" />
</property>
</bean>
<bean id="myBaseTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="myTransactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
<!--
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="save">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="edit*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="disPlay*">PROPAGATION_REQUIRES_NEW</prop>
-->
</props>
</property>
</bean>
<bean id="UsersDAO" class="com.notepad.dao.UsersDAO">
<property name="sessionFactory">
<ref bean="mySessionFactory" />
</property>
</bean>
<bean id="userTarget" class="com.notepad.bussies.UserService">
<property name="usersDao">
<ref local="UsersDAO" />
</property>
</bean>
<bean id="UserService" parent="myBaseTransactionProxy">
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="target">
<ref local="userTarget" />
</property>
</bean>
</beans>
评论
我运行怎么有警告
16:07:43,671 WARN Cglib2AopProxy:250 - Unable to proxy method [public final org.hibernate.SessionFactory org.springframework.orm.hibernate3.support.HibernateDaoSupport.getSessionFactory()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
16:07:43,671 WARN Cglib2AopProxy:250 - Unable to proxy method [public final org.springframework.orm.hibernate3.HibernateTemplate org.springframework.orm.hibernate3.support.HibernateDaoSupport.getHibernateTemplate()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
16:07:43,671 WARN Cglib2AopProxy:250 - Unable to proxy method [public final void org.springframework.orm.hibernate3.support.HibernateDaoSupport.setHibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
16:07:43,671 WARN Cglib2AopProxy:250 - Unable to proxy method [public final void org.springframework.orm.hibernate3.support.HibernateDaoSupport.setSessionFactory(org.hibernate.SessionFactory)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
16:07:43,671 WARN Cglib2AopProxy:250 - Unable to proxy method [public final void org.springframework.dao.support.DaoSupport.afterPropertiesSet() throws java.lang.IllegalArgumentException,org.springframework.beans.factory.BeanInitializationException] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
16:07:43,671 WARN Cglib2AopProxy:250 - Unable to proxy method [public final org.hibernate.SessionFactory org.springframework.orm.hibernate3.support.HibernateDaoSupport.getSessionFactory()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
16:07:43,671 WARN Cglib2AopProxy:250 - Unable to proxy method [public final org.springframework.orm.hibernate3.HibernateTemplate org.springframework.orm.hibernate3.support.HibernateDaoSupport.getHibernateTemplate()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
16:07:43,671 WARN Cglib2AopProxy:250 - Unable to proxy method [public final void org.springframework.orm.hibernate3.support.HibernateDaoSupport.setHibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
16:07:43,671 WARN Cglib2AopProxy:250 - Unable to proxy method [public final void org.springframework.orm.hibernate3.support.HibernateDaoSupport.setSessionFactory(org.hibernate.SessionFactory)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
16:07:43,671 WARN Cglib2AopProxy:250 - Unable to proxy method [public final void org.springframework.dao.support.DaoSupport.afterPropertiesSet() throws java.lang.IllegalArgumentException,org.springframework.beans.factory.BeanInitializationException] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
发表评论
我的相册
skoda_1.jpg
共 1 张
共 1 张
最近加入圈子
最新评论
-
将action得到的值,通过re ...
我找了半天都没找出原因来, 谢了!
-- by grape927 -
spring+hibernate之applic ...
datasource ne???
-- by 111111 -
spring+hibernate之applic ...
datasource ne???
-- by 111111 -
Spring用回调HibernateCal ...
你做的这个工具类 感觉就没内部类灵活了
-- by congpeixue -
struts+spring整合测试
GOO000000000000000G
-- by tigerphoebe







评论排行榜