Skip to content

Latest commit

 

History

History
73 lines (54 loc) · 3.21 KB

README.md

File metadata and controls

73 lines (54 loc) · 3.21 KB

Tomcat JPA Sample

This is the readme file for the Tomcat JPA Sample application.

Technology stack

Tomcat.

Tomcat Maven Plugin (which), last version 2.2 implies Tomcat 7.

Tomcat 7.0.57, which implies:

  • Servlet Spec 3.0
  • JSP Spec 2.2
  • EL Spec 2.2
  • Java 6 and later

Java 1.7.0_67.

H2 in its latest stable version 1.3.176.

Hibernate 4.3 requires Jandex. Jandex is in turn detected by Weld as available on classpath and used. Jandex-related classes in Weld are then not compatible with slf4j, they throw NumberFormatException as they try to push slf4j messages with "{}" possibly to JBoss logging which expects messages with "{0}" formatted for MessageFormat. This occurs on log level trace.

Therefore Hibernate 4.2 is chosen.

JPA provider Hibernate 4.2 in its latest stable version 4.2.17.Final, which implies:

  • JPA 2.0

Bean Validation provider Hibernate Validator in its latest stable version 5.1.3.Final.

CDI provider Weld in its latest current version 2.2.8.Final. which implies:

  • CDI 1.2

DeltaSpike for CDI extensions:

Juplo Hibernate 4 Maven plugin to generate create table sql script.

Running locally

  1. Install standalone Tomcat.
  2. Configure its conf/tomcat-users.xml:
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <user username="admin" password="" roles="manager-gui,manager-script"/>
  1. Copy the h2-1.3.176.jar to lib/ directory.
  2. Configure the conf/server.xml, find the <GlobalNamingResources> and insert into it:
    <!-- sample h2 database -->
    <Resource name="jdbc_sample" auth="Container" type="javax.sql.DataSource" username="sa"
        password="" driverClassName="org.h2.Driver" 
        url="jdbc:h2:~/data/sample/sample;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE;MVCC=TRUE"
        maxActive="10" maxIdle="4" maxWait="10000" />
  1. Start Tomcat startup.sh.
  2. Verify the datasource is bound to the global JNDI jdbc_sample: Tomcat global JNDI resources.
  3. Execute mvn to build the war and deploy / re-deploy it to the running Tomcat server.
  4. Access the home page.
  5. Refresh the home page repeatedly to get new sample values generated.

Database create table sql script generation

Execute mvn -Pdb to (re-)generate create table sql script in setup/sql/tomcat-jpa-sample-schema-generated.ddl file.