This repository contains sample projects for transactions in java solutions. I've created these project to apprehend a comprehensive study the transactions in the mixture flavor of frameworks out there. All the projects are tested on; -Wildfly 10 -MySQL
If you decide to download the source code and run, before doing so, please consult the "Setup" section.
In this project you will find transactions in three aspects; -Programmatic Transactions(run ProgrammaticTransactionMainApp.java), -Declarative Transactions using xml(run DeclarativeTransactionXMLMainApp.java), -Declarative Transactions using annotations(run DeclarativeTransactionAnnotationMainApp.java).
This is a standalone project that I've used JPA Implementation of Hibernate, entity manager is used to manage entities. In this project I've demonstrated the Programmatic Transactions only.
In this project I am demonstating how Hibernate's Declarative JTA transactions can be handled using spring framework. This is a web application that I couldn't turn it into a standalone project which is very tricky as I saw on the internet. It required lots of configuration for a demonstation purpose, I found it unnecessary and decided to turn this into a web app. To be able to run this project, you'll need to make configurations on your Wildfly Server.
In all of my projects, I've used lombok for boiler plate code. If you are going to run the project; -In Intellij: https://projectlombok.org/setup/intellij -In Eclipse and flavors: https://projectlombok.org/setup/eclipse
CREATE SCHEMA transactionproject DEFAULT CHARACTER SET utf8 ;
CREATE TABLE transactionproject.employee (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(45) NULL,
department VARCHAR(45) NULL,
UNIQUE INDEX id_UNIQUE (id ASC),
PRIMARY KEY (id));
- Add a management user in wildfly,
- Download the mysql connector jar
- In the modules folder of Wildfly home, create these folders sequence: com\mysql\main
- Move the mysql jar here
- In the same folder, create a file named “module.xml” and paste content(take the name of the jar file into consideration);
- Open the “standalone.xml” file and in the section add the following above h2 entry;
-
Go to the line and add the below line(mind the connection details) jdbc:mysql://localhost:3306/transactionproject mysql root root 127.0.0.1 transactionproject root root mysql
-
Start the server and you will see jar loaded and the datasource is created
INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) WFLYJCA0018: Started Driver service with driver-name = mysql INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) WFLYJCA0001: Bound data source [java:/mysqlDataSource]
- Go to http://narayana.io/downloads/index.html download the NTA Binary the ear
- Move the ear file JBOSSHOME standalone\deployments
- open browser and navigate to http://localhost:8080/nta/