Describe the bug
When invoking an endpoint annotated with @UnitOfWork(readOnly = true), you'll see in the server logs that Hibernate is flushing entities. This should be a read-only transaction, with read-only entities, so no flushing should be going on, I think.
To Reproduce
Steps to reproduce the behavior:
flushing a total of 17 entities and 68 collectionsExpected behavior
No entities should be flushed.
Additional context
鈹咺ssue is synchronized with this Jira Story
鈹咺ssue Type: Story
鈹咶ix Versions: Dockstore 1.9
鈹哠print: Sprint 37 Lobster
鈹咺ssue Number: DOCK-1393
Initial findings, seems like we need to add an explicit flushMode to readonly transactions.
@UnitOfWork(readOnly = true, flushMode = FlushMode.MANUAL)
In org.hibernate.internal.SessionImpl#flushBeforeTransactionCompletion, there is:
final boolean doFlush = isTransactionFlushable()
&& getHibernateFlushMode() != FlushMode.MANUAL;
I thought I saw somewhere that setting a Hibernate transaction to readonly should override flush mode, but it doesn't seem to be the case.
Our read-only transactions don't seem to be read-only. I was able to save a change to the database from a readOnly=true annotated method. Confusing...
I've managed to convince myself this isn't too bad by debugging through it.
Although the dirty-check is being short-circuited by the read-only status, Hibernate is still iterating through all entities, if only to see they don't need to be persisted.
Probably going to close this as is, but going to mull over it, and if others any have thoughts...
This probably partially explains why DTOs are faster -- this is pattern we've been moving to.
Probably my preference long term (that and the GA4GH api change)