Hey guys, I'm having trouble inserting Geometry data into my PostGIS database, I was able to insert into a normal table just fine using a tutorial I found. I have modified the code to work with my MultiLineString Geometry field however I keep getting an error when I try and insert.
The variable 'r' is my Roads class which is just a class with two variables (and accessor methods for them), an int and a org.postgis.MultiLineString geometry field.
Hibernate version:
3.2.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="com.lmco.afuo.roads.Road" table="roads">
<id name="gid" column="gid" type="java.lang.Integer">
<generator class="sequence">
<param name="sequence">roads_gid_seq</param>
</generator>
</id>
<property name="geometry" column="the_geom" type="org.postgis.MultiLineString" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
try {
MultiLineString line = null;
tx = session.beginTransaction();
while( read from file ) {
(...) code to read data from a file and format into doubles
Point p1 = new Point(x1, y1);
p1.setSrid(-1);
Point p2 = new Point(x2, y2);
p2.setSrid(-1);
Point[] p = new Point[2];
p[0] = p1;
p[1] = p2;
LineString[] ls = new LineString[1];
ls[0] = new LineString(p);
line = new MultiLineString(ls);
System.out.println(line.toString());
r.setGeometry(line);
createRoad(r);
}
tx.commit();
line = null;
r = null;
} catch (IOException e) {
log.fatal(e.getMessage());
}
Full stack trace of any exception that occurs:
07:36:11,389 INFO Environment:514 - Hibernate 3.2.5
07:36:11,404 INFO Environment:547 - hibernate.properties not found
07:36:11,404 INFO Environment:681 - Bytecode provider name : cglib
07:36:11,435 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
07:36:11,529 INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
07:36:11,545 INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
07:36:11,701 INFO Configuration:553 - Reading mappings from resource : Road.hbm.xml
07:36:11,842 INFO HbmBinder:300 - Mapping class: com.lmco.afuo.roads.Road -> roads
07:36:11,873 INFO Configuration:1541 - Configured SessionFactory: null
07:36:11,873 DEBUG InitSessionFactory:113 - classic factory
07:36:11,998 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
07:36:11,998 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
07:36:11,998 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
07:36:12,013 INFO DriverManagerConnectionProvider:80 - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost/temp
07:36:12,029 INFO DriverManagerConnectionProvider:86 - connection properties: {user=peckb1, password=****}
07:36:12,279 INFO SettingsFactory:89 - RDBMS: PostgreSQL, version: 8.2.4
07:36:12,279 INFO SettingsFactory:90 - JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.2 JDBC3 with SSL (build 505)
07:36:12,326 INFO Dialect:152 - Using dialect: org.hibernate.dialect.PostgreSQLDialect
07:36:12,326 INFO TransactionFactoryFactory:34 - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
07:36:12,341 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
07:36:12,341 INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
07:36:12,341 INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
07:36:12,341 INFO SettingsFactory:154 - JDBC batch size: 15
07:36:12,341 INFO SettingsFactory:157 - JDBC batch updates for versioned data: disabled
07:36:12,341 INFO SettingsFactory:162 - Scrollable result sets: enabled
07:36:12,357 INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): disabled
07:36:12,357 INFO SettingsFactory:178 - Connection release mode: auto
07:36:12,357 INFO SettingsFactory:205 - Default batch fetch size: 1
07:36:12,357 INFO SettingsFactory:209 - Generate SQL with comments: disabled
07:36:12,357 INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
07:36:12,357 INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
07:36:12,357 INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
07:36:12,357 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
07:36:12,357 INFO SettingsFactory:225 - Query language substitutions: {}
07:36:12,357 INFO SettingsFactory:230 - JPA-QL strict compliance: disabled
07:36:12,357 INFO SettingsFactory:235 - Second-level cache: enabled
07:36:12,357 INFO SettingsFactory:239 - Query cache: disabled
07:36:12,357 INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider
07:36:12,357 INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
07:36:12,357 INFO SettingsFactory:263 - Structured second-level cache entries: disabled
07:36:12,373 INFO SettingsFactory:283 - Echoing all SQL to stdout
07:36:12,373 INFO SettingsFactory:290 - Statistics: disabled
07:36:12,373 INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
07:36:12,373 INFO SettingsFactory:309 - Default entity-mode: pojo
07:36:12,373 INFO SettingsFactory:313 - Named query checking : enabled
07:36:12,420 INFO SessionFactoryImpl:161 - building session factory
07:36:12,888 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
MULTILINESTRING((-74.65061950683594 39.87829780578613,-74.65056610107422 39.878252029418945))
07:36:13,060 DEBUG SQL:401 - select nextval ('roads_gid_seq')
Hibernate: select nextval ('roads_gid_seq')
MULTILINESTRING((-74.65067672729492 39.87835121154785,-74.65061950683594 39.87829780578613))
07:36:13,279 DEBUG SQL:401 - insert into roads (the_geom, gid) values (?, ?)
Hibernate: insert into roads (the_geom, gid) values (?, ?)
07:36:13,482 WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: null
07:36:13,482 ERROR JDBCExceptionReporter:78 - Batch entry 0 insert into roads (the_geom, gid) values (<stream of 607 bytes>, 21) was aborted. Call getNextException to see the cause.
07:36:13,482 WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: XX000
07:36:13,482 ERROR JDBCExceptionReporter:78 - ERROR: parse error - invalid geometry
07:36:13,513 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.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:106)
at com.lmco.afuo.roads.RAIDtoPostgres.main(RAIDtoPostgres.java:96)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into roads (the_geom, gid) values (<stream of 607 bytes>, 21) was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2530)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1317)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2592)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 8 more
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.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:106)
at com.lmco.afuo.roads.RAIDtoPostgres.main(RAIDtoPostgres.java:96)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into roads (the_geom, gid) values (<stream of 607 bytes>, 21) was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2530)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1317)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2592)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 8 more
Name and version of the database you are using:
PostgreSQL 8.2 with PostGIS 1.1.7