Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

JTA 1.2 - It's Not Your Grandfather's Transactions Anymore!

DZone's Guide to

JTA 1.2 - It's Not Your Grandfather's Transactions Anymore!

· Java Zone
Free Resource

Just released, a free O’Reilly book on Reactive Microsystems: The Evolution of Microservices at Scale. Brought to you in partnership with Lightbend.

Java Transaction API 1.2 aka  JSR 907 (*), which is part of Java EE 7, adds 2 important new features :  @Transactional and  @TransactionScoped
Prior to JTA 1.2, transactions were delegated to EJBs. By doing that, the developer was shielded from doing low-level JTA/JTS transaction handling as all of this was transparently handeld by the EJB container. With CMT ( Container-managed transaction), the default behaviour, the EJB container intercept calls so that it can interpose the required transaction plumbings. So this was, on one hand, handy because transactions were basically managed transparently but it also required, on the other hand, to use EJBs.
The new  @Transactional annotation solve this by basically bringing the semantics of those EJB transaction attributes in managed beans without any dependencies on the EJB container. So the  @Transactional annotation provides the ability to declaratively control transaction boundaries on managed beans. Under the hood, this capability is provided by a CDI interceptor that handle the necessary transaction plumbings (suspend, resume, commit, ...). In a nutshell, @Transactional bring the ease of CMT transactions to various Java EE Components (Servlet, JAX-RS, etc.) without requiring to use EJBs. 
The new  @TransactionScoped annotation provides the ability to specify a standard CDI scope to define bean instances whose lifecycle is scoped to the currently active JTA transaction. This simple  code driven post explain and demonstrate such a behaviour in action.
(*) For the curious who might wonder why some JSRs start in the 9xx range, there's a simple explanation for that. Those specifications are referred, in JCP parlance, as " Grandfathered JSRs" because those specifications have originally been developed outside of the JCP.

Strategies and techniques for building scalable and resilient microservices to refactor a monolithic application step-by-step, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Published at DZone with permission of Reza Rahman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}