Java how to - JPA and RDB

Use JPA (Hibernate) with RDB:

One need a RDB dialect for Hibernate, but Oracle actually provide that - one just need to extract and build:

$ jar xvf rdb$jdbc_home:rdb_ext.jar "RdbDialect.java"
$ set file/attr=rfm:stm RdbDialect.java
$ convert/fdl=nla0: RdbDialect.java RdbDialect.java
$ purge RdbDialect.java
$ create/dir [.org.hibernate.dialect]
$ ren RdbDialect.java [.org.hibernate.dialect]
$ javac -classpath 'hibpath' "[.org.hibernate.dialect]RdbDialect.java"

Note that this Rdb dialect works with Hibernate 3.6 but it does not work with Hibernate 5.0 - I have not tried with other versions, so 3.6 is the safe choice.

And with a [.META-INF]persistence.xml like this:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
   <persistence-unit name="test">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <class>testrdb.T1</class>
      <exclude-unlisted-classes/>
      <properties>
          <!--<property name="show_sql">true</property>-->
          <property name="hibernate.connection.driver_class" value="oracle.rdb.jdbc.rdbThin.Driver"/>
          <property name="hibernate.connection.url" value="jdbc:rdbThin://localhost:1701/dka3:[rdb]test"/>
          <property name="hibernate.connection.username" value="xxxxxx"/>
          <property name="hibernate.connection.password" value="xxxxxx"/>
          <property name="hibernate.connection.pool_size" value="5"/>
          <property name="hibernate.dialect" value="org.hibernate.dialect.RdbDialect"/>
      </properties>
   </persistence-unit>
</persistence>

Then it is ready to rock and roll:

// disable Hibernate logging (outcomment for debugging)
Logger.getLogger("org.hibernate").setLevel(Level.OFF);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("test");
EntityManager em = emf.createEntityManager();
...
em.close();
emf.close();

For a general intro to JPA see here.