Wednesday, December 19, 2007

Oracle Spatial and TopLink 11g

This spring I was blogging about Oracle Spatial object type oracle.spatial.geometry.JGeometry support in TopLink Essentials JPA - Oracle Spatial and TopLink Essentials JPA. But time dont wait, and we already have TopLink 11g that comes with Oracle JDeveloper 11g Technical Preview 2. In TopLink 11g support for JGeometry object type is much simplified and can be used in more convenient way.

Developed sample application -, contains Model and ViewController projects. In Model part, TopLink 11g is used to build persistence layer. In ViewController part, User Interface is developed with ADF Faces Rich Client. In order to run developed sample application you need to have Oracle MapViewer demo dataset MVDEMO in your database. You can download dataset from OTN and install it into your database as separate schema.

So, what are the main changes comparing to my previous post. Main news - support for Oracle Spatial object type oracle.spatial.geometry.JGeometry mapping and querying is provided out of the box by TopLink 11g. However, its important to know that this support is available with TopLink libraries and not with TopLink Essentials. What you need to do is to:

1. Configure a StructConverter with annotation on any of your entities. This configuration is performed only once for all entities.

@StructConverter(name = "JGeometry", converter = "")

2. For any attribute that you want to map to a type converted by specified StructConverter, @Convert annotation must be used:

private JGeometry location;

You can find this configuration I have done in Cities entity:

And in fact, its everything related about what developer should care when converting oracle.sql.Struct to oracle.spatial.geometry.JGeometry. Simple, isn't it? :-)

Sample application contains the same logic as one developed previously, queryCitiesSpatially() method in Session bean receives 4 parameters from Client and invokes named query - Cities.sampleQuery:

Named query Cities.sampleQuery is defined in separate class - Cities_SessionCustomizer. This class implements SessionCustomizer and creates expression with SDO_RELATE spatial operator. Class code:

Class with named query should be declared as Session Customizer Class in persistence.xml:

In ViewController project I have used ADF Faces Rich Client that comes with JDeveloper 11g, really amazing thing. One important thing related to ViewController, when I developed everything and was trying to Run application, I got exception - oracle.spatial.geometry.JGeometry class not found. It was quite strange to me, since I have added this library in Model project. Solution was to put sdoapi.jar into this directory - jdevstudio1111\lib\java\shared\oracle.toplink.ojdbc\

Developed User Interface part looks pretty cool. You can enter values and get result for spatial operator in table below:

In Cities data table you can notice Detach button, this button allows to open table in separate window. However, its not pop-up functionality, its function provided by ADF Faces Rich Client. This function allows to have in the same window several screens:

I think, such simplified Oracle Spatial object type usage in Object-Relational mapping, can greatly improve Spatial integration into enterprise systems.


Unknown said...

I've been searching and I can't seem to find the oracle.toplink.annotations directory...which jar file is this package located in?

Anonymous said...

your app doesnt work.
how can i configure my integreted weblogic in jdev11.
error is:
Error is: 'java.lang.ClassNotFoundException: oracle.spatial.geometry.JGeometry'
java.lang.ClassNotFoundException: oracle.spatial.geometry.JGeometry

Anonymous said...


//import oracle.toplink.annotations.Convert;
//import oracle.toplink.annotations.StructConverter;

i dont know from where i can gat this libraries?jar?
where should i put it in my jdev11?

i only have there
import org.eclipse.persistence.annotations.Convert;
import org.eclipse.persistence.annotations.StructConverter;

Andrej Baranovskij said...


Sample was done with JDev Technology Preview, when there was no EclipseLink libraries, but only TopLink. You should just use EclipseLink libraries you are mentioning, it should be the same as old ones from TopLink.