【发布时间】:2010-08-11 04:25:32
【问题描述】:
我之前已经发布过这个问题,但由于线程有点旧,我想我没有得到回复,很抱歉duplicating 但我的问题与春季交易有关。
我在 Spring 事务管理方面遇到了类似的问题。我正在使用休眠作为 ORM 框架。下面是我使用spring事务管理的应用程序的spring配置文件的摘录。
<context:annotation-config/>
<context:property-placeholder location="classpath:spring.properties"/>
<tx:annotation-driven transaction-manager="transactionManager"/>
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="find*" read-only="true"/>
<tx:method name="get*" read-only="true"/>
<tx:method name="create*" rollback-for="Exception"/>
<tx:method name="update*" rollback-for="Exception"/>
<tx:method name="remove*" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="ServiceOperation" expression="execution(* com.shaikh.demo.*Service.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="ServiceOperation"/>
</aop:config>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
我所有的 *Service 类都由 @Transactional 注释进行注释。
在我的休眠 DTO 类中,我正在修改每个 get* 方法的返回值,如下所示,因为我想删除所有非 ascii 字符。数据库中的数据用于只读目的,仅用于列出记录,在此之前我需要删除造成问题的非 ascii 字符。数据库是 Oracle 11g。
例如对于属性 accountNumber
public String getAccountNumber(){
return StringHelper.removeNonAscii(this.accountNumber);
}
我读到我们正在更改 DTO 对象的状态并使其变脏,因此休眠将这些脏对象刷新到数据库中。我可以在日志中看到更新语句。
我的问题是:
1.) 我正在使 DTO 对象变脏,但我已将 get* 相关方法标记为只读,因此休眠如何刷新对数据库的更改。
2.) 如何在不更改数据库数据的情况下解决与此非 Ascii 字符相关的问题。我错过了什么吗?
【问题讨论】:
标签: hibernate spring transactions dto