Compile and Run application with different ORM frameworks


IMPORTANT PRE-REQUISITES

1. Set up environment to compile and run the sample application

The following script must be run for each of the terminal session:

Windows:   > quickstart/ttquickstartenv.bat
Unix/Linux:   $ . quickstart/ttquickstartenv.sh OR
$ source quickstart/ttquickstartenv.csh

2. Set up sample database, user accounts and the TPTBM table

The following command should be run once to set up the sample database, user accounts and the TPTBM table.

Windows or Unix/Linux:   > cd quickstart/sample_code/j2ee_orm
> ttIsql -connStr "DSN=sampledb_1122" -f tptbm.sql

3. If necessary, install the Apache Ant build tool.

For each ORM framework, an Ant build script is provided to configure, build and execute the application based on the properties of the ORM framework installation. The Apache Ant build tool has to be installed if not present.

After installation, make sure the Operating System environment variable PATH includes the path to the 'ant' executable.

The Ant build scripts have been tested with Apache Ant version 1.9.2.

4. install ORM framework and configure build.properties

Each Ant build script reads values from file quickstart/sample_code/j2ee_orm/build.properties. This file specifies the locations of build dependencies including the location of the TimesTen JDBC driver jar file and the location of the ORM installation. This file also specifies the common benchmark execution parameters.

Make sure property timesten.jdbc.driver.jar and the home.dir of the ORM installation are set correctly in file build.properties:

This application has been tested with EclipseLink 2.0.2, 2.1.1, 2.4.0 and 2.5.1, OpenJPA 2.0.1, 2.2.0 and 2.2.2, and Hibernate 3.6.0, 3.6.10.Final, 4.1.5.SP1 and 4.3.1.Final.

  

How to compile and run the sample ORM application

ORM Framework Ant build script Persistence configuration Compile and Run
JPA with EclipseLink 1. Install EclipseLink 2 and then set the required properties listed above in build.properties based on the installation.

2. To build and run the demo execute this sequence of Ant tasks under directory quickstart/sample_code/j2ee_orm:

ant -f build-jpa-eclipselink2.xml clean
ant -f build-jpa-eclipselink2.xml package
ant -f build-jpa-eclipselink2.xml run

JPA with OpenJPA 1. Install the OpenJPA 2 distribution and set the required properties listed above in build.properties based on the installation.

2. To build and run the demo execute this sequence of Ant tasks under directory quickstart/sample_code/j2ee_orm:

ant -f build-jpa-openjpa2.xml clean
ant -f build-jpa-openjpa2.xml package
ant -f build-jpa-openjpa2.xml run

JPA with Hibernate 3 (or Hibernate 4)
1. Install the Hibernate 3 (or Hibernate 4) distribution and set the required properties listed above in build.properties based on the installation.

2. Note that this configuration uses the included Hibernate dialect called TimesTenDialect1122. This dialect is not included in current versions of the Hibernate distribution. The TimesTenDialect1122 class is compiled and packaged into this application. This is the recommended Hibernate dialect for TimesTen 11.2.2 applications.

3. To build and run the demo execute this sequence of Ant tasks under directory quickstart/sample_code/j2ee_orm:

ant -f build-jpa-hibernate3.xml clean
ant -f build-jpa-hibernate3.xml package
ant -f build-jpa-hibernate3.xml run

or, if Hibernate 4 is used:

ant -f build-jpa-hibernate4.xml clean
ant -f build-jpa-hibernate4.xml package
ant -f build-jpa-hibernate4.xml run

Refer to the Troubleshooting section if any error about SLF4J pops up.

Hibernate 3 (or Hibernate 4)
1. Install the Hibernate 3 distribution and then set the required properties listed above in build.properties based on the installation.

2. Note that this configuration uses the included Hibernate dialect class called TimesTenDialect1122. It has been optimized for SQL features in TimesTen version 11.2.2. This dialect is not included in current versions of the Hibernate distribution. The TimesTenDialect1122 class is compiled and packaged into this application. This is the recommended dialect for applications that use TimesTen version 11.2.2 or greater.

3. To build and run the demo execute this sequence of Ant tasks under directory quickstart/sample_code/j2ee_orm:

ant -f build-hibernate3.xml clean
ant -f build-hibernate3.xml package
ant -f build-hibernate3.xml run

or, if Hibernate 4 is used:

ant -f build-jpa-hibernate4.xml clean
ant -f build-jpa-hibernate4.xml package
ant -f build-jpa-hibernate4.xml run

Refer to the Troubleshooting section if any error about SLF4J pops up.

 

Troubleshooting

While building the application with newer versions of the Hibernate distribution, the following error may occur:

  SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

The reason is that newer versions of the Hibernate distribution use the SLF4J logging facade. SLF4J requires at least one of several available log framework adapter jar files that may not be included in the Hibernate distribution. The error occurs if an SLF4J log adapter jar file is not on the CLASSPATH when running this configuration.

To solve this problem download the SLF4J JDK 1.4 logging adapter jar file for the same version of SLF4J that is included in the Hibernate distribution. SLF4J distributions are available at http://www.slf4j.org/dist/.

For example, if the Hibernate distribution includes the slf4j-api-1.5.8.jar file then download the corresponding SLF4J 1.5.8 distribution. Extract the slf4j-jdk14-1.5.8.jar file from the distribution and place it in the same Hibernate directory as the slf4j-api-1.5.8.jar file. Additional information on logging can be found at http://www.slf4j.org/ and in the Hibernate documentation.

 

Hibernate SQL Dialect for TimesTen 11.2.2

TimesTen Quick Start Guide provides a Hibernate SQL Dialect class that helps to avoid SQL syntax incompatibilities for Hibernate applications that use TimesTen.

To compile and configure the TimesTenDialect1122 class for your application, follow these steps:

  1. Go to directory quickstart/sample_code/j2ee_orm/config/hibernate3
    (or quickstart/sample_code/j2ee_orm/config/hibernate4 if Hibernate 4 is used)
  2. Edit the build.properties file in this directory. Set the hibernate.home.dir property to reference the location of the local Hibernate distribution.
  3. The Apache Ant build tool is used to compile the class. Make sure that the directory containing the ant executable is included on the PATH environment variable. Execute these commands from this directory to compile the class.

    ant clean
    ant

  4. If the dialect class compiles successfully it will be located in a subdirectory as 'build/org/hibernate/dialect/TimesTenDialect1122.class'. This class must be included in the Hibernate application's CLASSPATH environment variable in order for it to be used by the application.
  5. To configure a Hibernate application to use the TimesTenDialect1122 class the hibernate.dialect session property must be set to 'org.hibernate.dialect.TimesTenDialect1122'. The example hibernate.cfg.xml configuration file below demonstrates a TimesTen Hibernate session configuration that uses the TimesTenDialect1122 class.
    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    
    <hibernate-configuration>
    
      <!-- a SessionFactory instance -->
      <session-factory name="Tptbm">
    
        <!-- properties -->
        <property name="hibernate.connection.url">jdbc:timesten:TPTBM</property>
        <property name="hibernate.connection.username"></property>
        <property name="hibernate.connection.password"></property>
        <property name="hibernate.connection.driver_class">com.timesten.jdbc.TimesTenDriver</property>
    
        <property name="hibernate.dialect">org.hibernate.dialect.TimesTenDialect1122</property>
        <property name="hibernate.connection.isolation">2</property>
    
        <property name="hibernate.jdbc.fetch_size">32</property>
        <property name="hibernate.jdbc.batch_size">256</property>
        <property name="hibernate.jdbc.batch_versioned_data">true</property>
    
        <property name="hibernate.jdbc.use_streams_for_binary">false</property>
        <property name="hibernate.jdbc.use_get_generated_keys">false</property>
        <property name="hibernate.jdbc.use_scrollable_resultset">false</property>
    
        <property name="hibernate.cache.use_query_cache">false</property>
        <property name="hibernate.cache.use_second_level_cache">false</property>
    
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.connection.pool_size">4</property>
    
        <!-- mapping file -->
        <mapping resource="META-INF/Tptbm.hbm.xml"/>
    
      </session-factory>
    
    </hibernate-configuration>
    
    

 

For more information on Java programming with Oracle TimesTen, refer to the Oracle TimesTen In-Memory Database Java Developer's Guide.