[hibernate-dev] Lambda usage to run a code block in an isolated transaction

2016-09-14 Thread Sanne Grinovero
Today porting some benchmark code to Hibernate ORM 5.2 I had several difficulties around the fact that the code now needs to be different depending on transactions being container managed or not. My goal was to have a single benchmark test which I could compile once and run in either JavaSE or CMT

Re: [hibernate-dev] Lambda usage to run a code block in an isolated transaction

2016-09-14 Thread Steve Ebersole
The problem with "execute in isolation" here is that the "isolation" aspect refers to being isolated from any current transaction. It says nothing about whether that stuff-to-execute should itself be transacted. This is why, for example, you see IsolationDelegate accept a `transacted` boolean arg

Re: [hibernate-dev] Lambda usage to run a code block in an isolated transaction

2016-09-14 Thread Steve Ebersole
As another option we could define something like this on SF: T doInIsolatedSession(BiFunction work); T doInIsolatedSession(Function work); The spec here would be to make sure any current transaction is suspended (JTA), a new Session opened, the function performed and the suspended transaction i

Re: [hibernate-dev] Lambda usage to run a code block in an isolated transaction

2016-09-14 Thread Sanne Grinovero
On 14 September 2016 at 20:32, Steve Ebersole wrote: > The problem with "execute in isolation" here is that the "isolation" aspect > refers to being isolated from any current transaction. It says nothing > about whether that stuff-to-execute should itself be transacted. This is > why, for exampl

Re: [hibernate-dev] Lambda usage to run a code block in an isolated transaction

2016-09-14 Thread Steve Ebersole
"Better" according to whom? ;) I personally very much dislike the kind of API explosion this kind of thing leads to. On Wed, Sep 14, 2016 at 2:59 PM Sanne Grinovero wrote: > On 14 September 2016 at 20:32, Steve Ebersole wrote: > > The problem with "execute in isolation" here is that the "isol

Re: [hibernate-dev] Lambda usage to run a code block in an isolated transaction

2016-09-14 Thread Steve Ebersole
Also, why do you keep defining this in terms of Session, rather than SessionFactory? On Wed, Sep 14, 2016 at 3:01 PM Steve Ebersole wrote: > "Better" according to whom? ;) > > I personally very much dislike the kind of API explosion this kind of > thing leads to. > > > On Wed, Sep 14, 2016 at 2

Re: [hibernate-dev] Lambda usage to run a code block in an isolated transaction

2016-09-14 Thread Sanne Grinovero
On 14 September 2016 at 21:02, Steve Ebersole wrote: > Also, why do you keep defining this in terms of Session, rather than > SessionFactory? I mentioned that same doubt in my first email of this thread. I think I prefer Session as that's what people interact with most of the time, and it's a bet

Re: [hibernate-dev] Lambda usage to run a code block in an isolated transaction

2016-09-14 Thread Steve Ebersole
Most transaction systems do not support nested transactions On Wed, Sep 14, 2016 at 3:13 PM Sanne Grinovero wrote: > On 14 September 2016 at 21:02, Steve Ebersole wrote: > > Also, why do you keep defining this in terms of Session, rather than > > SessionFactory? > > I mentioned that same doubt

Re: [hibernate-dev] Lambda usage to run a code block in an isolated transaction

2016-09-14 Thread Steve Ebersole
Naming aside, my favorite approach is to have an "executor" available from SessionFactory for accepting this functional-interface (lambda). The executor would be configured with whether to isolate the work and whether to transact it. Something like: Executor getExecutor(boolean isolated, boolean