-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Persisting geometry in Oracle spatial using Hibernate 3.0
PostPosted: Fri Aug 26, 2005 12:07 pm 
Newbie

Joined: Fri Aug 26, 2005 9:40 am
Posts: 2
Location: Denmark
Hi
I am trying to persist geometry objects as Oracle SDO_GEOMETRY data.
In my test case, I am able to persist an Oracle JGeometry object using oracle.sql.STRUCT in the table column via JDBC.

Code:
        int elementInfo[] = {1, 2, 1};
        double ordinates[] =
                 {719662.21, 6182614.33, 719673.88, 6182600.43};
        JGeometry lineString =
                 new JGeometry(2002, 1234, elementInfo, ordinates);
        STRUCT geoObj = JGeometry.store(lineString, connection);
        PreparedStatement prepStatement =
                 connection.prepareStatement
                     ("insert into MisoGeometry (id, geometry)
                        values (MisoGeometry_id_seq.nextval, ?)");
        prepStatement.setObject(1, geoObj, Types.STRUCT);


I now want Hibernate to do the save.
What I have tried is to implement a UserType (STRUCTUserType, see below) containing a STRUCT object, and then map it to the table (user type, mapping and table below).
However, now I cannot instantiate my test case. HbmBinder is able to resolve properties of class MisoGeometry and table MISOGEOMETRY, but startup fails at reference resolving with
Code:
java.lang.reflect.InvocationTargetException
(see below).

Has anyone succeeded saving geometry using Hibernate 3.0?
Thanks

Hibernate version: 3.0.5

Mapping documents:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class
        name="dk.xxx.myproject.matrikulaerbasis.model.MisoGeometry"
        table="MisoGeometry"
    >
        <id
            name="id"
            column="id"
            type="long"
        >
            <generator class="native">
              <param name="sequence">misogeometry_id_seq</param>     
            </generator>
        </id>
        <property
            name="geometry"
            type="STRUCTUserType"
            update="true"
            insert="true"
        >
            <column
                name="geometry"
                sql-type="sdo_geometry"
            />
        </property>
    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
public class STRUCTUserType implements UserType {

    private STRUCT oracleSqlStructUserType;

    public STRUCT getOracleSqlStructUserType() {
        return oracleSqlStructUserType;
    }

    public void setOracleSqlStructUserType(STRUCT oracleSqlStructUserType) {
        this.oracleSqlStructUserType = oracleSqlStructUserType;
    }

    public int[] sqlTypes() {
        return new int[Types.STRUCT];
    }

    public Class returnedClass() {
        return STRUCT.class;
    }

    public boolean equals(Object obj1, Object obj2) throws HibernateException {
        return ((STRUCT)obj1).equals((STRUCT)obj2);
    }

    public int hashCode(Object o) throws HibernateException {
        return ((STRUCT)o).hashCode();
    }

    public Object nullSafeGet(ResultSet resultSet, String[] strings, Object o) throws HibernateException, SQLException {
        STRUCT geometry = (STRUCT) resultSet.getObject(strings[0]);
        return resultSet.wasNull() ? null : geometry;
    }

    public void nullSafeSet(PreparedStatement preparedStatement, Object o, int i) throws HibernateException, SQLException {
        if (o == null) {
            preparedStatement.setNull(i, Types.STRUCT);
        } else {
            preparedStatement.setObject(i, (STRUCT) o);
        }
    }

    public Object deepCopy(Object o) throws HibernateException {
        if(o==null) {
            return null;
        } else {
            STRUCT geo = (STRUCT) o;
            STRUCT newGeo;
            try {
                newGeo = new STRUCT(geo.getDescriptor(),geo.getConnection(),geo.getAttributes());
            } catch (SQLException e) {
                e.printStackTrace();
                throw new HibernateException("deepCopy SQLException", e);
            }
            return newGeo;
        }
    }

    public boolean isMutable() {
        return false;
    }

    public Serializable disassemble(Object o) throws HibernateException {
        return (Serializable) deepCopy(o);
    }

    public Object assemble(Serializable serializable, Object o) throws HibernateException {
        return deepCopy(serializable);
    }

    public Object replace(Object o, Object o1, Object o2) throws HibernateException {
        return (STRUCT) o;
    }


Full stack trace of any exception that occurs:

As you can see, HbmBinder is able to resolve properties of class MisoGeometry and table, but fails at reference resolving with java.lang.reflect.InvocationTargetException.

Code:
...
17:29:26,644 DEBUG [org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1262)] myproject/hibernate/SessionFactory<-org.dom4j.tree.DefaultAttribute@977dd28 [Attribute: name resource value "dk/xxx/myproject/matrikulaerbasis/model/misogeometry.hbm.xml"]
17:29:26,644 INFO  [org.hibernate.cfg.Configuration.addResource(Configuration.java:444)] Mapping resource: dk/xxx/myproject/matrikulaerbasis/model/misogeometry.hbm.xml
17:29:26,654 DEBUG [org.hibernate.util.DTDEntityResolver.resolveEntity(DTDEntityResolver.java:42)] trying to locate http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd in classpath under org/hibernate/
17:29:26,654 DEBUG [org.hibernate.util.DTDEntityResolver.resolveEntity(DTDEntityResolver.java:53)] found http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd in classpath
17:29:26,684 INFO  [org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:260)] Mapping class: dk.xxx.myproject.matrikulaerbasis.model.MisoGeometry -> MisoGeometry
17:29:26,684 DEBUG [org.hibernate.cfg.HbmBinder.bindProperty(HbmBinder.java:1099)] Mapped property: id -> id
17:29:26,684 DEBUG [org.hibernate.cfg.HbmBinder.bindProperty(HbmBinder.java:1099)] Mapped property: geometry -> geometry
...
17:29:26,814 DEBUG [org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:964)] resolving reference to class: dk.xxx.myproject.sag.model.Sag
17:29:26,814 DEBUG [org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:964)] resolving reference to class: dk.xxx.myproject.sag.model.Sagshaendelse
17:29:26,814 DEBUG [org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:964)] resolving reference to class: dk.xxx.myproject.sagspakke.model.Sagspakke
Cannot instantiate test(s): java.lang.reflect.InvocationTargetException

Process finished with exit code 1


Name and version of the database you are using:
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options

The generated SQL (show_sql=true):
No SQL to access table MISOGEOMETRY is created due to the reflection error. The table definition is:

Code:
create table myproject.MisoGeometry (
    id number(19,0) not null,
    geometry sdo_geometry,
    primary key (id)
);
create sequence myproject.misogeometry_id_seq;


Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 28, 2005 7:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Well the stack trace would be most helpful :)

But one quick observation: Does STRUCTUserType exist in a package? If so, you need the FQN in the mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 4:28 am 
Newbie

Joined: Fri Aug 26, 2005 9:40 am
Posts: 2
Location: Denmark
I added the FQN to the mapping and deployed to my local WebSphere. Now the error says:
Code:
org.hibernate.MappingException: property mapping has wrong number of columns: dk.kms.minimaks.matrikulaerbasis.model.MisoGeometry.geometry type: dk.kms.minimaks.matrikulaerbasis.model.STRUCTUserType

I have traversed the different "wrong number of columns" postings, but I can't quite find the answer.
Please help
Thanks

The complete stack:

Code:
[30-08-05 09:59:25:057 CEST]  879c1a9 SystemErr     R org.hibernate.MappingException: property mapping has wrong number of columns: dk.kms.minimaks.matrikulaerbasis.model.MisoGeometry.geometry type: dk.kms.minimaks.matrikulaerbasis.model.STRUCTUserType
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:326)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:188)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:839)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1000)
   at dk.kms.minimaks.startup.MinimaksApplicationStartup.start(MinimaksApplicationStartup.java:63)
   at com.ibm.websphere.startupservice.EJSRemoteStatelessdk_kms_minimaks_startup_Minimaks_3a6fd8e2.start(Unknown Source)
   at com.ibm.websphere.startupservice._AppStartUp_Stub.start(_AppStartUp_Stub.java:252)
   at com.ibm.ws.startupservice.StartBeanInfo.start(StartBeanInfo.java:283)
   at com.ibm.ws.startupservice.StartUpModule.appStart(StartUpModule.java:152)
   at com.ibm.ws.startupservice.StartUpApplication.start(StartUpApplication.java:110)
   at com.ibm.ws.startupservice.StartUpService.stateChanged(StartUpService.java:391)
   at com.ibm.ws.runtime.component.ApplicationMgrImpl.stateChanged(ApplicationMgrImpl.java:477)
   at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectEvent(DeployedApplicationImpl.java:791)
   at com.ibm.ws.runtime.component.DeployedApplicationImpl.setState(DeployedApplicationImpl.java:157)
   at com.ibm.ws.runtime.component.DeployedApplicationImpl.setState(DeployedApplicationImpl.java:153)
   at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:589)
   at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:301)
   at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:578)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
   at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
   at com.tivoli.jmx.modelmbean.MMBInvoker.invoke(MMBInvoker.java:46)
   at com.tivoli.jmx.modelmbean.MMBInvoker.invokeOperation(MMBInvoker.java:115)
   at com.tivoli.jmx.modelmbean.DynamicModelMBeanSupport.invoke(DynamicModelMBeanSupport.java:409)
   at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:323)
   at com.tivoli.jmx.GenericMBeanSupport.invoke(GenericMBeanSupport.java:178)
   at com.tivoli.jmx.MBeanAccess.invoke(MBeanAccess.java:113)
   at com.tivoli.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:290)
   at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:659)
   at com.ibm.ws.console.core.mbean.MBeanHelper.invoke(MBeanHelper.java:141)
   at com.ibm.ws.console.appdeployment.ApplicationDeploymentCollectionAction.perform(ApplicationDeploymentCollectionAction.java:336)
   at org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1791)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1586)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
   at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
   at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
   at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
   at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
   at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
   at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1095)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java(Compiled Code))
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:201)
   at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:125)
   at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:286)
   at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
   at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:116)
   at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
   at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
   at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
   at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:652)
   at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:458)
   at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:912)


Top
 Profile  
 
 Post subject: Any News on this Issue?
PostPosted: Tue Sep 13, 2005 10:23 am 
Newbie

Joined: Tue Sep 23, 2003 12:03 pm
Posts: 7
Location: Wisconsin
I am a Oracle Spatial user as well as a Hibernate user, yet I've never been able to plug the two together. Has there been any breakthroughs on this by anyone?

Thanks

_________________
the man comes around


Top
 Profile  
 
 Post subject: Help...any news/updates on Spatial/Geometry?
PostPosted: Tue Nov 01, 2005 9:17 pm 
Newbie

Joined: Tue Feb 15, 2005 10:58 pm
Posts: 4
Michael, or anyone,
were you able to finally persist JGeometry types? Did you ever solve the column mapping error you posted? I am also embarking on an Oracle/Spatial/Hibernate project and I need to do exactly the same thing.
If you have any updates or samples or answers, please post!

Thx,
Eric Weiss


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.