deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Struberg <strub...@yahoo.de.INVALID>
Subject Re: DeltaSpike Data - What application servers are supported?
Date Wed, 10 May 2017 09:22:44 GMT
Hi Konrad, John!

Hmm not sure about ContainerManagedTransactionStrategy. 

Look at the code, this is probably not named properly. It is essentially a no-op TransactionStrategy.
It delegates through without doing something.

This is useful if you GUARANTEED have a ContainerManagedTransation in an outer level. 
E.g. if you have some existing code using DeltaSpike @Transactional, and you know that you
ALWAYS have e.g. a @Stateless @WebService calling your code.
We cannot rename this now because otherwise the Alternatives enabled in various beans.xml
files would go bonkers...

So if you are about to use e.g. an @ApplicationScoped @Transactional bean without any EJBs
involved at all, then you should rather use the BeanManagedUserTransactionStrategy.
This one leverages the UserTransaction functionality provided by the server. If a JTA Transaction
is already active then it would simply do nothing. So in this case it really behaves the same
like ContainerManagedTransactionStrategy. 

But if there is NO active Transaction, then it will use the UserTransaction API to open a
transaction and to commit/rollback on this very layer when leaving the intercepted method.
Subsequently invoked @Transactional CDI beans - and even EJBs! - will just take this open
transaction and work with it.
So this works perfectly fine in cases where you only use CDI but also when you wildly mix
EJBs and CDI beans.
I use this in production for quite a few projects.

Note that the EntityManagerProducer you need to provide must use a container provided EntityManagerFactory,
otherwise your EntityManager won't integrate with JTA.
A sample can be found here:
https://github.com/struberg/lightweightEE/blob/jtacdi11/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/tools/EntityManagerProducer.java#L40


hth.

LieGrue,
strub

> Am 09.05.2017 um 01:50 schrieb John D. Ament <johndament@apache.org>:
> 
> Konrad,
> 
> When you specify globalAlternatives, you don't need to specify anything in
> beans.xml
> 
> RE which strategy to use, it'll be the one that matches your transaction
> mode.  If you're using plain JTA just use
> ContainerManagedTransactionStrategy.
> 
> John
> 
> On Mon, May 8, 2017 at 3:56 PM Instantiation Exception <
> instantiationexception@gmail.com> wrote:
> 
>> John,
>> 
>> I want to clarify one thing. When I use
>> META-INF/apache-deltaspike.properties with
>> globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.
>> TransactionStrategy=org.apache.deltaspike.jpa.impl.transaction.
>> ContainerManagedTransactionStrategy
>> 
>> should I use alternative in beans.xml? And which one?
>> org.apache.deltaspike.jpa.impl.transaction.ContainerManagedTransactionStr
>> ategy
>> or
>> org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy
>> 
>> Best regards,
>> Konrad
>> 
>> On Fri, Mar 3, 2017 at 2:57 PM, John D. Ament <johndament@apache.org>
>> wrote:
>> 
>>> Ondrej,
>>> 
>>> I agree as well.  It definitely should be more turn key in this respect.
>>> 
>>> John
>>> 
>>> On Fri, Mar 3, 2017 at 8:53 AM Ondrej Mihályi <ondrej.mihalyi@gmail.com>
>>> wrote:
>>> 
>>>> Hi John,
>>>> 
>>>> It sounds to me that DeltaSpike could be improved to make a
>> sophisticated
>>>> guess to infer the default value of this configuration from the
>> container
>>>> it is running in. At least for WildFly and maybe some other containers
>>>> where people report problems.
>>>> 
>>>> Just an idea :)
>>>> 
>>>> Ondrej
>>>> 
>>>> 2017-03-03 12:05 GMT+01:00 John D. Ament <johndament@apache.org>:
>>>> 
>>>>> Hi Konrad,
>>>>> 
>>>>> What that's referring to is that you need to create a
>>>>> META-INF/apache-deltaspike.properties and add the following line:
>>>>> 
>>>>> globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.
>>>>> TransactionStrategy=org.apache.deltaspike.jpa.impl.transaction.
>>>>> ContainerManagedTransactionStrategy
>>>>> 
>>>>> I do something similar to  you, and it works perfect.  I'm using
>> maven
>>> to
>>>>> build a WAR file, so it just goes in
>>>>> src/main/resources/META-INF/apache-deltaspike.properties
>>>>> 
>>>>> John
>>>>> 
>>>>> On Fri, Mar 3, 2017 at 3:38 AM Instantiation Exception <
>>>>> instantiationexception@gmail.com> wrote:
>>>>> 
>>>>>> Hi,
>>>>>> 
>>>>>> In my company projects we use WildFly. In the past I tried few
>> times
>>> to
>>>>> use
>>>>>> DeltaSpike Data, but it didn't work. I configured everything
>>> according
>>>> to
>>>>>> documentation. In pure CDI scenario it worked. But when I created
>>>>>> @Dependent @Repository and injected it to @Stateless EJB I got some
>>>>>> transaction errors when tried to call EJB methods. In
>> documentation I
>>>> see
>>>>>> warning:
>>>>>> 
>>>>>> Some containers do not support BeanManagedUserTransactionStrategy!
>>> As
>>>>> JTA
>>>>>>> has still some portability issues even in Java EE 7, it might
be
>>>>> required
>>>>>>> that you implement your own TransactionStrategy. We will think
>>> about
>>>>>>> providing an acceptable solution for this.
>>>>>> 
>>>>>> 
>>>>>> Is it about WildFly? Is WildFly supported?
>>>>>> 
>>>>>> Best regards,
>>>>>> Konrad
>>>>>> 
>>>>> 
>>>> 
>>> 
>> 


Mime
View raw message