dao的删除代码:
public class ScoreDaoHibernate extends HibernateDaoSupport implements ScoreDao {
public void delete(String id) {
Score dd=(Score)this.getHibernateTemplate().get(Score.class, id);
System.out.println(dd.getCourseName());
this.getHibernateTemplate().delete(dd);
//throw new RuntimeException();
}
}
测试文件代码:
public class transactiontest extends AbstractTransactionalDataSourceSpringContextTests {
private ScoreDao scoreDao;
protected String[] getConfigLocations() {
return new String[] { "classpath:applicationContextoracle.xml" };
}
public void onSetUpBeforeTransaction() throws Exception {
scoreDao = (ScoreDao) applicationContext.getBean("scoreDao");
}
public void testCjScoreDTODao() {
scoreDao.delete("3");
//List<Score> aa=scoreDao.findAllBySno("0403010616");
//System.out.println(aa.size());
System.out.println("-----------------");
}
}
配置文件代码:
<?xml version="1.0" encoding="UTF-8"?>
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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:202.118.121.112:1521:orcl">
</property>
<property name="username" value="scott"></property>
<property name="password" value="gl"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/gl/model/Score.hbm.xml</value>
<value>com/gl/model/Userpassword.hbm.xml</value>
<value>com/gl/model/Xuanke.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
</props>
</property>
</bean>
<!-- the transactional semantics... -->
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
<bean id="scoreDao" class="com.gl.dao.hibernate.ScoreDaoHibernate"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
请大家帮我看看是什么原因啊????