• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

application managed EM can be either JTA or resource-local?

 
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It says that application managed entity managers can be either resource-local or JTA. I didn't understand this.

What I thought is,

  • A transaction with a container-managed entity managers is called "JTA Transaction".
  • A transaction with an application-managed entity managers is called "resource-local Transaction".


  • If application-managed entity manager can be either JTA or resource-local, then what is the difference between JTA and resource-local?

    Confused
     
    Ranch Hand
    Posts: 383
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi. All container-managed entity managers are JTA managers. An application-managed entity manager may be either JTA or resource-local, and they are always extended. The difference is that when it is JTA, it simply is used in a distributed transaction with EJB calls, Timer creations, other resource managers and so on. When the UserTransaction (either container-managed or bean-managed, it doesn't really matter) is rolled back, all of the mentioned operations are rolled back. If you used resource-local manager (EntityTransaction interface to demarcate transactions), the rollback on the UserTransaction would not influence the entity manager operations. Hence, you will most likely use JTA in Java EE, whereas resource-local are designed to be usable in Java SE, when there is possibly no JTA implementation available.
    One more note - when you use an application-managed JTA entity manager and create them outside an active JTA transaction (for example, when you inject a manager factory and in @PostConstruct you create the entity manager), you call joinTransaction() before you call refresh(), persist(), merge() or remove(), so that these operations don't throw TransactionRequiredException. The JTA transaction may either be container- or bean-managed.
    Does this make sense?

    Raf
     
    Treimin Clark
    Ranch Hand
    Posts: 757
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Raf,

    Can you tell me in example that how to create an application-managed entity manager with JTA and resource-local transactions? This is the point what I couldn't understand.
     
    Raf Szczypiorski
    Ranch Hand
    Posts: 383
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Application-managed JTA:



    For resource local, in Java SE, with persistance-unit type set to "RESOURCE_LOCAL":

    Note that the above code does not have to be supported by an EJB container.

    Cheers.
     
    Treimin Clark
    Ranch Hand
    Posts: 757
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you Raf,

    Raf Szczypiorski wrote:
    Note that the above code does not have to be supported by an EJB container.



    Why did you say this?
     
    Raf Szczypiorski
    Ranch Hand
    Posts: 383
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    JPA specs, 7.2 Bootstrapping in Java SE Environments, page 154, and footnote #42, page 154:


    Use of these Java SE bootstrapping APIs may be supported in Java EE containers; however, support for such use is not required.



    So, basically, the answer is simple - because the specs say so ;-)

    Raf
     
    Treimin Clark
    Ranch Hand
    Posts: 757
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks again, Raf
     
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    then may I know what is the difference between container-managed entity managers JTA and application-managed entity managers JTA?
    Are there both same in terms of JTA?
     
    Ranch Hand
    Posts: 918
    IntelliJ IDE Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Fei,

    In the "container-managed entity manager" the container care about the life cycle for the involved resources (or more precisely the resource manager connection factory) and the application is focus only on the business. In the "application mode" the application (you can read here the developer) must care about the resource life cycle (e.g. it must close the factory), so in this case the application must focus on business and on resource life cycle.

    The JTA is only the transactional model.

    Regards,
    Mihai

     
    Fei Wong
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Mihai Radulescu,

    I roughly get your meaning. from the transaction model point of view, these 2 are no difference.
    while from the entity point of view, there is the difference. Am I correct?

    Thanks
     
    Mihai Radulescu
    Ranch Hand
    Posts: 918
    IntelliJ IDE Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yes.
    Both, JTA and RESOURCE_LOCAL describes transactions - for different purposes (see the upper post from Raf)

     
    reply
      Bookmark Topic Watch Topic
    • New Topic