« Return to Thread: Multiple EntityManagerFactories for the same DB - do i need JTA

Re: Multiple EntityManagerFactories for the same DB - do i need JTA

by mem12 :: Rate this Message:

| View in Thread

Hello,

thanks for your fast response.
So to confirm, you're saying if i'm using more than one JPA Persistence Unit in one JTA Transaction it has to be a 2PC no matter if they both point to the same Database/Datasource or not?
As i'm certain about using 2 PU's in my sample the result is that there's a misconfiguration with the DB or Spring config.

kind regards
Matt


Ludovic Orban-2 wrote:
If you want the changes you make via the different persistence units to be
part of the same transaction, you have to use a transaction manager.

Here's an example:

@Transactional
public void myBusinessMethod() {
  doSomeChangesUsingPersistenceUnit1();
  doSomeChangesUsingPersistenceUnit2();
}

If you want to guarantee that the changes made by
doSomeChangesUsingPersistenceUnit1 are rolled back when
doSomeChangesUsingPersistenceUnit2 fails, you have to use a transaction
manager. That obviously being only one example of guarantee a TM would
provide you with.

1PC is an optimization that automatically kicks in when only one resource
(ie, in your case: a single persistence unit) is being part of a
transaction. It is impossible for me to tell you exactly why you see it
happening but a probable cause is that you're only using one one PU when
you see this log which is quite normal. Other reasons would involve
incorrect configuration of your datasources, transaction manager or
incorrect transaction boundaries (ie: misplaced @Transactional tags or
Spring transactional AOP interceptor).



2012/1/12 mem12 <memcacher@gmail.com>

>
> Hello,
>
> i've a somewhat odd question i can't find an answer for.
> We've a modular application where each app which accesses the db has it's
> own entity manager factory and persistence unit. They all use the same DB
> and can be involved in a Transaction either alone or multiple at once.
> We're
> currently using Bitronix (through Spring) but are trying to evaluate the
> different vendors like Jboss, Atomikos, Bitronix, ... as we're unsure about
> the exact functionality.
> Everything seems to work just fine but today i was debugging a transaction
> which had to different EntityManagers involved but then during the commit
> phase the Bitronix Commiter class in the commit method figured there's only
> 1 single resource involved and therefore there's no need for 2PC (which is
> the main purpose of JTA, right?).
> So, to sum up, do i need JTA and 2PC when using multiple EntityManagers
> which all connect to the same DB?
>
> Thanks in advance.
> Matt
> --
> View this message in context:
> http://old.nabble.com/Multiple-EntityManagerFactories-for-the-same-DB---do-i-need-JTA-tp33126315p33126315.html
> Sent from the Bitronix Transaction Manager mailing list archive at
> Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

 « Return to Thread: Multiple EntityManagerFactories for the same DB - do i need JTA