业务bean:
[color=blue]@Transactional[/color]
public class PersonServiceBean implements PersonService {
@Resource private SessionFactory sessionFactory;
public void save(Person person){
sessionFactory.getCurrentSession().persist(person);
session,persist()
}
public void update(Person person){
sessionFactory.getCurrentSession().merge(person);
}
[color=red]@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)[/color]
public Person getPerson(Integer personId){
return (Person)sessionFactory.getCurrentSession().get(Person.class, personId);
}
public void delete(Integer personId){
sessionFactory.getCurrentSession().delete(
sessionFactory.getCurrentSession().load(Person.class, personId));
}
}
spring配置文件:
<aop:aspectj-autoproxy />
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driveClassName}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="${initialSize}"/>
<property name="maxActive" value="${maxActive}"/>
<property name="maxIdle" value="${maxIdle}"/>
<property name="minIdle" value="${minIdle}"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="mappingResources">
<list>
<value>com/tank/bean/Person.hbm.xml</value> </list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.use_query_cache">false</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
</props>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
<aop:config>
<aop:pointcut id="myPointCut" expression="execution(* com.tank.service..*.*(..))" />
<aop:advisor pointcut-ref="myPointCut" advice-ref="txAdvice"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="delete*" />
[color=red] <tx:method name="save*" read-only="true"/>[/color]
<tx:method name="update*" />
<tx:method name="*" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>
<bean id="personService" class="com.tank.service.impl.PersonServiceBean"/>
[b]
问题:[/b]
这个方法已经为只读,但仍能保存进数据库
业务bean已经被@Transactional了。
如果我在save()方法上在注明@Transactional(propagation=Propagation.SUPPORTES)的话,可以生效!!
什么原因?貌似管理也有啊!!!