[hibernate-dev] inSession / inTransaction

Chris Cranford crancran at gmail.com
Mon Jan 7 10:37:22 EST 2019


I have no objections to exposing them directly rather than being part of
the test infrastructure.

On 12/20/18 5:16 PM, Steve Ebersole wrote:
> On Thu, Dec 20, 2018 at 1:33 PM Gunnar Morling <gunnar at hibernate.org> wrote:
>
>> 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.
>>
> I've written many non-trivial apps in my past that did not use
> "DAO/repositories" etc.  Not sure why we'd choose to not implement
> something that is useful just because not everyone would use it.  To me, if
> something is repeatedly useful in writing tests... it tends to be
> more-or-less generally useful.
>
>
> One other thought is that inTransaction() should allow to return a result
>> value.
>>
> An over-loaded form perhaps, yes I can see that - but non-returning is
> valid as well.  So maybe:
>
> public interface SessionFactory ... {
>     ...
>     void inSession(Consumer<Session> action);
>     void inTransaction(Consumer<Session> action);
>     void inTransaction(Session session, Consumer<Session> action);
>
>     <T> T inSession(Function<Session,T> action);
>     <T> T inTransaction(Function<Session,T> action);
>     <T> T inTransaction(Session session, Function<Session,T> action);
> }
>
> and
>
> public interface Session ... {
>     void inTransaction(Consumer<Session> action);
>
>     <T> T inTransaction(Function<Session,T> action);
> }
> _______________________________________________
> 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