On Wed, 17 Jul 2019 at 09:59, Loïc MATHIEU <
loik...@gmail.com> wrote:
>
> Hi,
>
> So, do we create an "action plan" for this ?
+1
> 1. Add to the guide and the JavaDoc some warnings about it ? Something like the following :
> "If you use one of the Panache stream() operators, and access to the database during one of it's processing step, you must do this inside a transaction (so using the `@Transactional` annotation to the method)."
I'd also point out that the stream must be closed within the same
transaction (see below..)
> 2. As Stéphane suggested, generate an exception if the stream operation is used outside of a transaction (I vote no for this one as it may works so it's not mandatory)
Careful, it is mandatory at least for some databases: cursors are
(typically) destroyed at the end of any transaction scope. And when
you don't explicitly control a transaction, such transaction scope is
automatically created to span the single statement, so the cursor
would be destroyed right away: the effect is exactly the exception you
reported.
See e.g. PostgreSQL:
-
https://jdbc.postgresql.org//documentation/head/query.html#query-with-cursor
It *might* appear to work when we fetch all results in the first
batch; but that's not something we should force right? I'd rather have
people demand that explicitly by using list().stream() (the list()
obviously requests to fetch them all).
> 3. Implements "read only" transactions, as I understant, this needs to be propagated to the underlying Hibernate session (but is the session tied to the transaction in Quarkus ?)
I don't think it is yet, but we could read the transaction hints to
newly opened Hibernate sessions.
>
> I can open related issues if needed, I can easily provides a PR for 1) but I don't know how to implements 3) so maybe someone else can do it.
Many thanks for organizing this! If you could split this in issues,
that would be great.
Sanne
> To view this discussion on the web visit
https://groups.google.com/d/msgid/quarkus-dev/CAJLxjVFrViDfcYYa%2Btj449%2BrzNqDG5-WX_V8ExuWqSD2rJMqPw%40mail.gmail.com.