初学SSH框架,遇到一个小问题
小弟初学SSH框架,遇到一个小小的问题。比如我要对一条新闻进行增删改查。。增和查都可以修改到数据库,而删和改测试的时候都没有报错。但是数据库中却没被修改到。。
代码如下。。求大神指点
//通过ID查找新闻
public News findNewsById(int newsId) {
return (News) sessionFactory.openSession()
.get(News.class, newsId);
}
//更新新闻
public boolean updateNews(News news) {
try {
sessionFactory.openSession().update(news);
return true;
} catch (RuntimeException e) {
e.printStackTrace();
}
return false;
}
//删除新闻
public boolean deleteNews(News news) {
try {
sessionFactory.openSession().delete(news);
return true;
} catch (RuntimeException e) {
e.printStackTrace();
}
return false;
}
//保存新闻
public boolean saveNews(News news) {
try {
sessionFactory.openSession().save(news);
return true;
} catch (RuntimeException e) {
e.printStackTrace();
}
return false;
}
ApplicationContext.xml代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.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/onlineshopping">
</property>
<property name="username" value="root"></property>
<property name="password" value="daijiawei"></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>
<prop key="current_session_context_class">thread</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/mall/entity/User.hbm.xml</value>
<value>com/mall/entity/Goodscategory.hbm.xml</value>
<value>com/mall/entity/Goods.hbm.xml</value>
<value>com/mall/entity/Message.hbm.xml</value>
<value>com/mall/entity/News.hbm.xml</value>
<value>com/mall/entity/Chatrecord.hbm.xml</value>
<value>com/mall/entity/Order.hbm.xml</value>
<value>com/mall/entity/Orderdetail.hbm.xml</value>
</list>
</property>
</bean>
<!-- 声明事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 定义事务通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<!-- 定义切面,并将事务通知和切面组合(定义哪些方法应用事务规则) -->
<aop:config>
<aop:pointcut expression="execution(* com.mall.biz.*.*(..))"
id="transactionPointcut" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut" />
</aop:config>
<bean id="userDao" class="com.mall.dao.impl.UserDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="orderDao" class="com.mall.dao.impl.OrderDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="messageDao" class="com.mall.dao.impl.MessageDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="newsDao" class="com.mall.dao.impl.NewsDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 定义UserBizImpl,并给其属性userDao注入实例 -->
<bean id="orderBiz" class="com.mall.biz.impl.OrderBizImpl">
<property name="orderDao" ref="orderDao"></property>
</bean>
<bean id="messageBiz" class="com.mall.biz.impl.MessageBizImpl">
<property name="messageDao" ref="messageDao"></property>
</bean>
<bean id="newsBiz" class="com.mall.biz.impl.NewsBizImpl">
<property name="newsDao" ref="newsDao"></property>
</bean>
<bean id="userBiz" class="com.mall.biz.impl.UserBizImpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean name="userAction" class="com.mall.action.UserAction" scope="prototype">
<property name="userBiz" ref="userBiz"></property>
</bean>
<bean name="imageAction" class="com.mall.action.ImageAction"></bean>
<bean name="newsAction" class="com.mall.action.NewsAction">
<property name="newsBiz" ref="newsBiz"></property>
</bean>
</beans>