-->
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.  [ 1 post ] 
Author Message
 Post subject: Postgresql ,UserType,Geometry type,nullDafeSet
PostPosted: Mon May 02, 2005 7:08 am 
Newbie

Joined: Wed Apr 20, 2005 3:19 am
Posts: 5
How I can implement nullSafeSet(usertype) for PGpoint type?
PGpoint is a geometry type in PostgreSQL.

Following code dosnt work:


Code:
public void nullSafeSet(PreparedStatement statement, Object value, int index) throws HibernateException, SQLException {
        System.out.println("nullSafeSet");
        if (value == null) {
            statement.setNull(index, Types.OTHER);
        } else {
            PGpoint p =(PGpoint)value;
            statement.setString(index,"'"+p.getValue()+"'");
        }
       
    }



but nullSafeGet work correctly:


Code:
public Object nullSafeGet(ResultSet resultSet, String[] stringArray,
                              Object object) throws SQLException,
            HibernateException {
        System.out.println("nullSafeGet");
        if (resultSet.wasNull()) return null;
        PGpoint v=(PGpoint) resultSet.getObject(stringArray[0]);
        return v;

    }


And this is stack:

    May 2, 2005 3:05:12 PM org.hibernate.cfg.Environment <clinit>

    INFO: Hibernate 3.0
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Environment <clinit>
    INFO: using CGLIB reflection optimizer
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Environment <clinit>
    INFO: using JDK 1.4 java.sql.Timestamp handling
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Configuration configure
    INFO: configuring from resource: /hibernate.cfg.xml
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: /hibernate.cfg.xml
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Configuration addResource
    INFO: Mapping resource: Cities.hbm.xml
    May 2, 2005 3:05:13 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: mrb.postgresOnly.Cities -> Cities
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Configuration addResource
    INFO: Mapping resource: Points.hbm.xml
    May 2, 2005 3:05:13 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: mrb.postGIS.Points -> Points
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Configuration doConfigure
    INFO: Configured SessionFactory: null
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Configuration secondPassCompile
    INFO: processing extends queue
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Configuration secondPassCompile
    INFO: processing collection mappings
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Configuration secondPassCompile
    INFO: processing association property references
    May 2, 2005 3:05:13 PM org.hibernate.cfg.Configuration secondPassCompile
    INFO: processing foreign key constraints
    May 2, 2005 3:05:14 PM org.hibernate.dialect.Dialect <init>
    INFO: Using dialect: org.hibernate.dialect.PostgreSQLDialect
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default batch fetch size: 1
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Generate SQL with comments: disabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Order SQL updates by primary key: disabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
    INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    May 2, 2005 3:05:14 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
    INFO: Using ASTQueryTranslatorFactory
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query language substitutions: {}
    May 2, 2005 3:05:14 PM org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Using Hibernate built-in connection pool (not for production use!)
    May 2, 2005 3:05:14 PM org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Hibernate connection pool size: 20
    May 2, 2005 3:05:14 PM org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: autocommit mode: false
    May 2, 2005 3:05:14 PM org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql:mydb2
    May 2, 2005 3:05:14 PM org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: connection properties: {user=postgres, password=****}
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC batch size: 15
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC batch updates for versioned data: disabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Scrollable result sets: enabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC3 getGeneratedKeys(): disabled
    May 2, 2005 3:05:14 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
    INFO: Using default transaction strategy (direct JDBC transactions)
    May 2, 2005 3:05:14 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
    INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic flush during beforeCompletion(): disabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic session close at end of transaction: disabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory createCacheProvider
    INFO: Cache provider: org.hibernate.cache.EhCacheProvider
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Second-level cache: enabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Optimize cache for minimal puts: disabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Structured second-level cache entries: enabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query cache: disabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Echoing all SQL to stdout
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Statistics: disabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Deleted entity synthetic identifier rollback: disabled
    May 2, 2005 3:05:14 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default entity-mode: pojo
    May 2, 2005 3:05:14 PM org.hibernate.impl.SessionFactoryImpl <init>
    INFO: building session factory
    May 2, 2005 3:05:14 PM net.sf.ehcache.config.Configurator configure
    WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/F:/hibernate-3.0/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
    May 2, 2005 3:05:15 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
    INFO: Not binding factory to JNDI, no JNDI name configured
    May 2, 2005 3:05:15 PM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
    INFO: Checking 0 named queries
    Hibernate: select nextval ('cities_id_cities_seq')
    May 2, 2005 3:05:15 PM org.hibernate.util.JDBCExceptionReporter logExceptions
    WARNING: SQL Error: 0, SQLState: null
    May 2, 2005 3:05:15 PM org.hibernate.util.JDBCExceptionReporter logExceptions
    SEVERE: Batch entry 0 insert into Cities (name, location, id_cities) values ('myString', '5,5', 40) was aborted. Call getNextException to see the cause.
    May 2, 2005 3:05:15 PM org.hibernate.util.JDBCExceptionReporter logExceptions
    WARNING: SQL Error: 0, SQLState: 42804
    Hibernate: insert into Cities (name, location, id_cities) values (?, ?, ?)
    May 2, 2005 3:05:15 PM org.hibernate.util.JDBCExceptionReporter logExceptions
    SEVERE: ERROR: column "location" is of type point but expression is of type character varying
    May 2, 2005 3:05:15 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
    SEVERE: Could not synchronize database state with session
    org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:179)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
    at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:48)
    at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:656)
    at org.hibernate.impl.SessionImpl.prepareQueries(SessionImpl.java:832)
    at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:822)
    at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:857)
    at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
    at mrb.postgresOnly.readpostgresOnly.main(readpostgresOnly.java:22)
    Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into Cities (name, location, id_cities) values ('tehran', '', 40) was aborted. Call getNextException to see the cause.
    at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2392)
    at org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:386)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1257)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:334)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2435)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172)
    ... 10 more

    org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:179)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
    at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:48)
    at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:656)
    at org.hibernate.impl.SessionImpl.prepareQueries(SessionImpl.java:832)
    at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:822)
    at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:857)
    at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
    at mrb.postgresOnly.readpostgresOnly.main(readpostgresOnly.java:22)
    Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into Cities (name, location, id_cities) values ('tehran', '', 40) was aborted. Call getNextException to see the cause.
    at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2392)
    at org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:386)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1257)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:334)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2435)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172)
    ... 10 more
    Exception in thread "main"

_________________
MRB


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

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.