81,094
社区成员
发帖
与我相关
我的任务
分享
@Repository
public class BaseHibernateDao extends HibernateDaoSupport {
}
@Service
public class TestService extends BaseService {
@Autowired
TestDao testDao;
public void testTT(){
testDao.testTT();
}
}
@Service
public class TestDAO extends BaseHibernateDao{
public void testTT(){
String hql = " update Test set age= ? where id = 1000 ";
Query q = this.getSession(true).createQuery(hql);
q.setInteger(0, 3333333);
q.executeUpdate();
Test n = new Test();
n.setAddtime( new Date() );
n.age( new Long(101) );
n.setDatastr("22222222222");
n.setPid( Long.parseLong("sssssssssssss") );
//此处故意throw RuntimeException子类
session.save(n);
//为何log中没有spring 动态代理的信息,有事务回滚信息?数据库中还是更新了test表中的字段
}
}
http://forum.springframework.org/showthread.php?t=65541
spring官方贴<?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:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"
default-autowire="byName">
<context:property-placeholder location="classpath:proxool.properties" />
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="driver">
<value>${proxool.driver}</value>
</property>
<property name="driverUrl">
<value>${proxool.url}</value>
</property>
<property name="user">
<value>${proxool.username}</value>
</property>
<property name="password">
<value>${proxool.password}</value>
</property>
<property name="alias">
<value>${proxool.alias}</value>
</property>
<property name="houseKeepingSleepTime">
<value>${proxool.houseKeepingSleepTime}</value>
</property>
<property name="prototypeCount">
<value>${proxool.prototypeCount}</value>
</property>
<property name="maximumConnectionCount">
<value>${proxool.maximumConnectionCount}</value>
</property>
<property name="minimumConnectionCount">
<value>${proxool.minimumConnectionCount}</value>
</property>
<property name="trace">
<value>${proxool.trace}</value>
</property>
<property name="verbose">
<value>${proxool.verbose}</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="packagesToScan">
<list>
<value>com.x.domain</value>
</list>
</property>
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<aop:config proxy-target-class="true">
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.x.service.*.*(..))"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager" >
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="REQUIRED"/>
<tx:method name="select*" read-only="true" propagation="REQUIRED"/>
<tx:method name="find*" read-only="true" propagation="REQUIRED"/>
<tx:method name="load" read-only="true" propagation="REQUIRED"/>
<tx:method name="query" read-only="true" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED" isolation="READ_COMMITTED" />
<tx:method name="insert*" propagation="REQUIRED" isolation="READ_COMMITTED" />
<tx:method name="create" propagation="REQUIRED" isolation="READ_COMMITTED" />
<tx:method name="save*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
<tx:method name="update*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
<tx:method name="delete*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
<tx:method name="remove*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
<tx:method name="test*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
</tx:attributes>
</tx:advice>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">
<property name="hibernate.connection.proxool_provider_class">org.hibernate.connection.ProxoolConnectionProvider</property>
<property name="hibernate.proxool.xml">classpath*:proxool.xml</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">false</property>
<property name="hibernate.default_schema">managood</property>
<property name="hibernate.max_fetch_depth">2</property>
<property name="hibernate.default_batch_fetch_size">16</property>
<property name="hibernate.order_updates">true</property>
<property name="hibernate.generate_statistics">false</property>
<property name="hibernate.use_identifer_rollback">false</property>
<property name="hibernate.use_sql_comments">false</property>
<!-- Hibernate and JDBC -->
<property name="hibernate.jdbc.fetch_size">100</property>
<property name="hibernate.jdbc.batch_size">50</property>
<property name="hibernate.jdbc.batch_versioned_data">false</property>
<property name="hibernate.jdbc.use_scrollable_resultset">false</property>
<property name="hibernate.connection.autocommit">true</property>
<property name="hibernate.connection.release_mode">auto</property>
<!-- Hibernate and JDBC -->
<!-- hibernate cache -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_minimal_puts">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region_prefix">2ndCache</property>
<property name="hibernate.cache.use_structured_entries">true</property>
<!-- hibernate cache -->
<!-- hibernate transaction -->
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<!-- hibernate transaction -->
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<property name="hibernate.bytecode.use_reflection_optimizer">true</property>
<!-- hibernate event -->
<event type="post-commit-insert">
<listener class="com.x.service.HibernateEventService"/>
</event>
<!-- hibernate event -->
</session-factory>
</hibernate-configuration>