[hibernate-dev] inSession / inTransaction

Gunnar Morling gunnar at hibernate.org
Thu Dec 20 14:33:27 EST 2018


Hey,

When discussing this before, there were some doubts about its actual
usefulness in non-testing, real-world code. E.g. you'd typically
interact with multiple DAOs/repositories etc. and would have to
somehow pass the session to each of them.

One other thought is that inTransaction() should allow to return a result value.

--Gunnar
Am Do., 20. Dez. 2018 um 17:02 Uhr schrieb Steve Ebersole <steve at hibernate.org>:
>
> In tests we find our `#inSession` and `#inTransaction` methods very
> useful.  Which got me thinking that maybe we should support these on
> SessionFactory directly:
>
> public interface SessionFactory ... {
>     ...
>     void inSession(Consumer<Session> action);
>     void inTransaction(Consumer<Session> action);
>     void inTransaction(Session session, Consumer<Session> action);
> }
>
> and maybe even:
>
> public interface Session ... {
>     void inTransaction(Consumer<Session> action);
> }
>
>
> Objections?
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev


More information about the hibernate-dev mailing list