[postgis-users] Problems with persisting/mapping org.postgis.PGbox3d via Hibernate

Jank, Klaus (SCR US) klaus.jank at siemens.com
Wed Apr 4 15:00:55 PDT 2007


Hi,
 
I am writing an application which Hibernate to map spatial objects like
geometry to postgis. That works very well with a Hibernate User Type for
Geometry types such as Point, etc.
Now, I am trying to adapt the org.postgis.hibernate.GeometryType
implementation to make it work for org.postgis.PGbox3d. However since
the BinaryParser and Writer doesn't support boxes I don't know which
type mapping I should use. For example just writing a string in the
nullSafeGet and nullSafeSet doesn't work. I always get a
SQLGrammerException. 
Does anyone has similar problems or ideas. Thanks for help!!
Here is the detailed implementation of my Box3DType hibernate custom
type and the exception I get.
 
public class Box3DType implements UserType {

private static final int[] SQL_TYPES = { Types.OTHER };

public Object assemble(Serializable cached, Object owner)

throws HibernateException {

return cached;

}

public Object deepCopy(Object value) throws HibernateException {

return value;

}

public Serializable disassemble(Object value) throws HibernateException
{

return (Serializable) value;

}

public boolean equals(Object x, Object y) throws HibernateException {

if (x == y) {

return true;

} else if (x == null || y == null) {

return false;

} else {

return x.equals(y);

}

}

public int hashCode(Object arg0) throws HibernateException {

return 0;

}

public boolean isMutable() {

return false;

}

public Object nullSafeGet(ResultSet resultSet, String[] names, Object
owner)

throws HibernateException, SQLException {

PGbox3d result = null;

String box3d = resultSet.getString(names[0]);

if (box3d != null) {

result = new PGbox3d(box3d);

}

return result;

}

public void nullSafeSet(PreparedStatement statement, Object value, int
index)

throws HibernateException, SQLException {

if (value == null) {

statement.setString(index, null);

} else {

PGbox3d box = (PGbox3d) value;

statement.setString(index, box.getValue());

}

}

public Object replace(Object original, Object target, Object owner)

throws HibernateException {

return original;

}

public Class returnedClass() {

return PGbox3d.class;

}

public int[] sqlTypes() {

return Box3DType.SQL_TYPES;

}

}

 

Exception Output:

javax.persistence.RollbackException: Error while commiting the
transaction

at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:63)

at
com.siemens.fsp.gmg.gisdata.PostGisDBAccessStandaloneTest.testCreateGisC
ollection(PostGisDBAccessStandaloneTest.java:494)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)

at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at junit.framework.TestCase.runTest(TestCase.java:154)

at junit.framework.TestCase.runBare(TestCase.java:127)

at junit.framework.TestResult$1.protect(TestResult.java:106)

at junit.framework.TestResult.runProtected(TestResult.java:124)

at junit.framework.TestResult.run(TestResult.java:109)

at junit.framework.TestCase.run(TestCase.java:118)

at junit.framework.TestSuite.runTest(TestSuite.java:208)

at junit.framework.TestSuite.run(TestSuite.java:203)

at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUn
it3TestReference.java:128)

at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.ja
va:38)

at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:460)

at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:673)

at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:386)

at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:196)

Caused by: org.hibernate.exception.SQLGrammarException: Could not
execute JDBC batch update

at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java
:67)

at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.
java:43)

at
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249
)

at
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java
:92)

at
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java
:87)

at
org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher
.java:218)

at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEn
tityPersister.java:2159)

at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEn
tityPersister.java:2595)

at
org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:
51)

at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)

at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)

at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)

at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(
AbstractFlushingEventListener.java:298)

at
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEv
entListener.java:27)

at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)

at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)

at
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:10
6)

at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:53)

... 19 more

Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into box
(dataStatus, importLocalityMO, importSRID, box, importedBox, id) values
(123, TestImportMOBox, 32632, "BOX3D(101 102,203 204)", "BOX3D(101
102,203 204)", 01c98a7a11be89d90111be89e9620010) was aborted. Call
getNextException to see the cause.

at
org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleErr
or(AbstractJdbc2Statement.java:2497)

at
org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl
.java:399)

at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImp
l.java:1298)

at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:
347)

at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2St
atement.java:2559)

at
org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:4
8)

at
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242
)

... 34 more

 
SIEMENS

Klaus Jank 
Technical Liaison Manager Java 

Siemens Corporate Research, Inc. 
Software Engineering

755 College Road East 
Princeton, NJ 08540 
USA 

klaus.jank <mailto:klaus.jank at siemens.com> @siemens.com
+1 (609) 734 3581 (phone)
+1 (609) 734-6565 (fax)
+1 (650) 704 8746 (mobile)
https://java.siemens.com/jtf/ (intranet)

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070404/565b7986/attachment.html>


More information about the postgis-users mailing list