How To use Oracle TopLink 11g with Spring

Oracle TopLink 11g Preview

How-To use use Oracle TopLink JPA with the Spring Framework

Introduction

This how-to describes how Oracle TopLink can be used within a Spring Framework enabled application as the JPA provider. With the 11g Preview of Oracle TopLink developers now have access to a fully compliant JPA implementation with extensions enabling simplified access to TopLink's advanced Object-Relational functionality. This how-to is intended for developers with some experience using JPA within Spring. The steps provided can be easily used with Spring's Pet Clinic sample.

Step 1: Extending Spring for Oracle TopLink JPA

 

The Spring Framework provides support for plugging in any JPA provider. Through this standard mechanism you can specify the usage of Oracle TopLink with all of its JPA extensions for use within your Spring enabled application. This is accomplished through the use of a JPAVendor and a JPA Dialect. Within Spring 2.0 and higher you will find implementations of these for use with TopLink Essentials.

OracleTopLinkJpaDialect is derived from the TopLinkJpaDialect shipped in the Spring Framework 2.0.4. Customized for Oracle TopLink package names.

OracleTopLinkJpaVendorAdapter is derived from TopLinkJpaVendorAdapter

Here is the spring-toplink-jpa.jar including both the source and implementation of these two classes. These must be configured on your classpath along with the necessary Spring libraries.

If you already have a Spring application using TopLink Essentials as the JPA provider and are using only the JPA annotations, XML, and TopLink Essentials' JPA Extensions you can switch to Oracle TopLink simply by including thse additional classes and making the necessary changes to your application context XML.

Step 2: Modify your Spring Application Context XML


The Spring application context XML used by the application must be slightly modified to make use of the new JPA vendor adapater provided.

<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.OracleTopLinkJpaVendorAdapter">
   <property name="databasePlatform" value="oracle.toplink.platform.database.oracle.OraclePlatform" />
   <property name="showSql" value="true" />
</bean>

As you can see the only changes required are to specify the new JPA adapter class and to use the Oracle TopLink package names for the database platform configuration.

Summary

As shown in this how-to it is quite simple to use Oracle TopLink 11g Preview as your JPA provider within Spring. The classes provided to enable this will be contributed back into the Spring Framework project and will hopefully be available in an upcoming release.

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy