Spring - Transaction Readonly

前端 未结 2 891
臣服心动
臣服心动 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:03

    This post tells that the behaviour or the readOnly flag is persistence-mechanism-dependent.

    C. Yes, when using hibernate, it gives performance benefits by setting the flush mode to FLUSH_NEVER (as described in the linked post)

    B. Yes, JDBC calls do not require a transaction (hibernate requires one), so removing the @Transactional configuration trims all transaction management.

    A. I'd assume spring is calling connection.setReadOnly(true) but your JDBC driver doesn't support this

    The bottom-line is : don't use readonly transactions with plain JDBC.

    And another thing - transactions are supposed to span multiple queries. Don't make your transactions too fine-grained. Make them a unit of work.

提交回复
热议问题