Reputation: 189
My spring configuration:
<jee:jndi-lookup id="testDataSource" jndi-name="java:testDS" />
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="testDataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
My Java method:
@Transactional(readOnly = true)
public List find() {
jdbcTemplate.query("SELECT * FROM my_table;");
}
If I use the script below directly on the database (MySQL
):
LOCK TABLES my_table WRITE;
and then try to run the java code with a read-only transaction, it's still waiting for the table to be unlocked.
Shouldn't it return the data since the transaction is set as read-only?
Thanks
Upvotes: 1
Views: 3565
Reputation: 936
No, because WRITE lock prevents both reading and writing to a table from anyone not holding the lock. If you put READ instead, you will be able to execute your query.
BTW, readOnly does nothing in the database directly, it's just a hint to ORM layer that transaction is not expected to do any writing.
Upvotes: 2