Sample Hibernate application for OpenAccess data sources

Posted by Prashant Khare on 08-Apr-2015 08:46

This article demonstrates how to configure sample Hibernate application with OpenAccess data sources. It includes sample Hibernate application,
that can run SQL queries on OpenAccess data sources connected using OpenAccess JDBC driver. It also includes sample OpenAccessDialect class which allows
hibernate to generate the appropriate SQL’s for OpenAccess. This solution uses Emp class with annotations to map objects with the defined Emp table, having
EmpNo as a Primary Key and other columns consists few data types.
Step-by-Step Instructions to build a Hibernate application
 
It’s very simple to configure the Hibernate application with your OpenAccess data source via JDBC. All you need is
 

·        Eclipse

·        OpenAcess Server

·        OpenAccess JDBC driver

·        Hibernate package

 

1.      Create a java project in eclipse and add the attached application. Add the OpenAccess JDBC driver (oajc.jar) in build path to connect to the OpenAccess Server.

Add all the required Hibernate jars which can be downloaded from http://hibernate.org/. Your Application will looks like as shown below

 

 

2.      The sample dialect class contains definition of data types and scalar functions supported by OpenAccess. As shown below, this dialect class

should be the part of hibernate package “org.hibernate.dialect “.

 

 

3.      Define the OpenAccess server configuration details and dialect class name in hibernate.cfg.xml file. Hibernate requires to know in advance where

to find the mapping information that defines how your Java classes relate to the database tables. It also requires a set of configuration settings

related to database and other related parameters. All such information is usually supplied in this XML file.

Please note that property “hbm2ddl.auto” is set as “create”, which will recreate the Emp table every time you runs the application,

You can modify it according to your needs.

4.      This application is ready to run and can be triggered from “HibernateMain.java”. File “input1.sql” contains few examples of select queries to execute

via hibernate HQL and file “input2.sql” contains few examples of scalar functions defined in the OpenAccessDialect class. These files will execute against

your configured OpenAccess data source and generates the corresponding output files.

 
 
Download ZIP File

All Replies

Posted by Prashant Khare on 07-Dec-2015 03:36

The mentioned steps to setup Hibernate application are applicable to both OpenAccess 7.2 and OpenAccess 8.0

Thanks,

Prashant

Posted by Prasanna Anireddy on 14-Dec-2015 09:16

Thanks Prashant

This thread is closed