Spring - Transaction Readonly

前端 未结 2 896
臣服心动
臣服心动 2020-12-23 17:42

Just wanted your expert opinions on declarative transaction management for Spring. Here is my setup:

  1. DAO layer is plain old JDBC using Spring JdbcTemplate (No
2条回答
  •  臣服心动
    2020-12-23 18:10

    A. Do I have to say get* as readonly? All my get* methods are pure read DB operations. I do not wish to run them in any transaction context. How serious is the above error?

    Actually, you probably still want to run all of your get()s in the context of a transaction, to make sure that you are getting consistent reads. If on the other hand, you don't care about this, you can set the transaction level accordingly.

    C. Why would anyone want to have transactional methods where readonly = true? Is there any practical significance of this configuration?

    1. To help protect against errant writes within get()` methods
    2. For optimization purposes. Not only can Hibernate make use of this information, as Bozho mentioned, but some databases/JDBC drivers can also be make use of this info.

提交回复
热议问题