InterSystems Implementation Reference for Java Third Party APIs
The InterSystems Hibernate Dialect is an implementation of the Hibernate dialect interface. Since every vendor’s implementation of SQL is slightly different, the dialect interface allows vendors to create custom Hibernate mappings for a specific database. Vendor-provided dialect implementations are distributed as part of Hibernate.
This chapter provides technical details about the InterSystems Hibernate Dialect. The following topics are discussed:
Java Persistence Architecture (JPA) is the recommended persistence technology for complex object hierarchies in Java projects. InterSystems currently supports JPA via the Hibernate implementations of the JPA specifications. Hibernate is an open source framework from JBoss that acts as a wrapper around JDBC to provide object/relational mapping (ORM) services for relational databases. Hibernate provides a vendor-neutral persistence service, which may be a requirement for some projects.
The InterSystems Hibernate Dialect is an implementation of the Hibernate dialect interface. Since every vendor’s implementation of SQL is slightly different, Hibernate includes vendor-provided "dialects" that customize its mappings to specific databases. Current Hibernate distributions include a high performance, customized InterSystems dialect class.
When to Use Hibernate
Hibernate provides the infrastructure to persist objects to relational tables. Essentially, it is a wrapper around JDBC that allows you to focus on working with objects while transparently handling conversion between objects and tables in SQL queries. Hibernate can be used in most environments, but it is not always the best option. Here are some considerations to bear in mind:
Hibernate is helpful when you have a complex but static object model. You must know what your data looks like and how the classes interact before you map them to your InterSystems IRIS table model.
Since Hibernate objects are cached, other applications should never interact with the data while Hibernate is accessing it. If you are working in an environment with real-time data that must remain accessible to other applications, you should consider XEP (see Persisting Java Objects with InterSystems XEP
) as a possible alternative.
Hibernate is good for common CRUD operations with simple querying, but more complex queries may be easier to write, or more efficient, using JDBC directly.
This section provides instructions for setting up your system to use Hibernate with InterSystems IRIS. The instructions assume that the correct versions of both InterSystems IRIS and Hibernate are installed and operational.
The following software must be installed on your system:
The instructions in this chapter refer to the following directories:
<install-dir> — the InterSystems IRIS installation directory. To locate <install-dir> in your instance of InterSystems IRIS, open the InterSystems terminal and issue the following command:
<hibernate_root> — your Hibernate installation directory.
Make the following changes to your system:
The intersystems-jdbc-3.0.0.jar file contains the InterSystems JDBC driver. If you haven't already done so, copy the appropriate version of intersystems-jdbc-3.0.0.jar from the default location to <hibernate_root>\lib.
Make sure the following items are on your Java classpath:
The jar files from <hibernate_root>\lib
The directory or directories where the Hibernate configuration files (hibernate.properties and hibernate.cfg.xml) are kept. By default, both files are in <hibernate_root>\etc.
In the Hibernate configuration files (either hibernate.properties or hibernate.cfg.xml), specify the connection information for your database, and the name of the InterSystems dialect class.
The following five configuration properties are required:
dialect — The fully qualified name of the InterSystems dialect class. The base dialect class is:
You can use a custom dialect class derived from this base class if you need to enable support for the Hibernate primary key generator classes.
driver_class — The fully qualified name of the InterSystems JDBC driver:
The JDBC driver is contained in the intersystems-jdbc-3.0.0.jar
file (see System Settings
username — Username for the InterSystems IRIS namespace you want to access (default is _SYSTEM).
password — Password for the InterSystems IRIS namespace (default is SYS).
url — The URL for the InterSystems JDBC driver. The format for the URL is:
is the IP address of the machine hosting InterSystems IRIS, <port>
is the SuperServer TCP port of your InterSystems IRIS instance, and <namespace>
is the namespace that contains your InterSystems IRIS database data (see Defining a JDBC Connection URL
for more details).
A typical entry in hibernate.properties would contain the following lines (change url, username, and password as appropriate for your system)):
The following example shows the same information as it would appear in hibernate.cfg.xml:
If the same property is set in both hibernate.properties and hibernate.cfg.xml, Hibernate will use the value from hibernate.cfg.xml.
The InterSystems Hibernate dialect consists of four files that should be located as follows
(where <hibernate> is hibernate-orm\hibernate-core\src\main\java\org\hibernate):
InterSystemsIRISDialect.java in <hibernate>\dialect\
IntersystemsIRISIdentityColumnSupport.java in <hibernate>\dialect\identity\
InterSystemsIRISSQLExceptionConversionDelegate.java in <hibernate>\exception\internal\
InterSystemsIRISJoinFragment.java in <hibernate>\sql\
Content Date/Time: 2019-08-22 05:46:30