include::../shared-doc/attributes.adoc[]

= bmt: Bean Managed Transactions with JPA and JTA
:author: Mike Musgrove
:level: Intermediate
:technologies: EJB, BMT

[abstract]
The `bmt` quickstart demonstrates Bean-Managed Transactions (BMT), showing how to manually manage transaction demarcation while accessing JPA entities.

:standalone-server-type: default
:archiveType: war
:uses-h2:
:uses-ds-xml:
:performance-scalability:

//*************************************************
// Shared CD and Product Release content
//*************************************************

== What is it?

The `bmt` quickstart demonstrates how to manually manage transaction demarcation while accessing JPA entities in {productNameFull}.

On occasion, the application developer requires finer grained control over the lifecycle of JTA transactions and JPA Entity Managers than the defaults provided by the Java EE container. This example shows how the developer can override these defaults and take control of aspects of the lifecycle of JPA and transactions.

When you run this example, you are presented with a *Use bean managed Entity Managers* checkbox.

* If you check the checkbox, it shows the developer responsibilities when injecting an Entity Manager into a managed (stateless) bean.
* If you uncheck the checkbox, shows the developer responsibilities when using JPA and transactions with an unmanaged component.

This example shows how to transactionally insert key value pairs into the database and demonstrates the requirements on the developer with respect to the JPA Entity Manager.

//*************************************************
// Product Release content only
//*************************************************

ifndef::EAPCDRelease[]

// Considerations for Use in a Production Environment
include::../shared-doc/development-shortcuts.adoc[leveloffset=+1]
// System Requirements
include::../shared-doc/system-requirements.adoc[leveloffset=+1]
// Use of {jbossHomeName}
include::../shared-doc/use-of-jboss-home-name.adoc[leveloffset=+1]
// Start the {productName} Standalone Server
include::../shared-doc/start-the-standalone-server.adoc[leveloffset=+1]
// Build and Deploy the Quickstart
include::../shared-doc/build-and-deploy-the-quickstart.adoc[leveloffset=+1]

== Access the Application

The application will be running at the following URL: http://localhost:8080/{artifactId}/.

You are presented with a simple form for adding key/value pairs, and a checkbox to indicate whether the updates should be executed using an unmanaged component. Effectively this will run the transaction and JPA updates in the servlet, not session beans. If the box is checked then the updates are executed within a session bean method.

. To list all pairs leave the *Key* input field empty.
. To add or update the value of a key, fill in the *Key* and *Value* input fields.
. Click the *Submit* button to see the results.

== Server Log: Expected Warnings and Errors

You will see the following warnings in the server log. You can ignore these warnings.

[source,options="nowrap"]
----
WFLYJCA0091: -ds.xml file deployments are deprecated. Support may be removed in a future version.

HHH000431: Unable to determine H2 database version, certain features may not work
----

// Undeploy the Quickstart
include::../shared-doc/undeploy-the-quickstart.adoc[leveloffset=+1]
// Run the Quickstart in Red Hat JBoss Developer Studio or Eclipse
include::../shared-doc/run-the-quickstart-in-jboss-developer-studio.adoc[leveloffset=+1]
// Debug the Application
include::../shared-doc/debug-the-application.adoc[leveloffset=+1]

endif::[]

//*************************************************
// CD Release content only
//*************************************************

ifdef::EAPCDRelease[]

// Getting Started with OpenShift
include::../shared-doc/cd-openshift-getting-started.adoc[leveloffset=+1]
//Prepare OpenShift for Quickstart Deployment
include::../shared-doc/cd-create-project.adoc[leveloffset=+1]
// Import the Latest {xpaasproduct-shortname} Image Streams and Templates
include::../shared-doc/cd-import-imagestreams-templates.adoc[leveloffset=+1]
// Deploy the {ProductShortName} Source-to-Image (S2I) Quickstart to OpenShift
include::../shared-doc/cd-deploy-project.adoc[leveloffset=+1]
// OpenShift Post Deployment Tasks: This is not currently needed.
// include::../shared-doc/cd-post-deployment-tasks.adoc[leveloffset=+1]

endif::[]

