Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate: Mapping a sequence to a serial (autoincr) field (Postgresql)  RSS feed

Samuel Cadieux
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heya Ranchers,

I never really used Hibernate before, in fact I use it since yesterday. After I successfully found
all the required libraries on internet, I made fictional classes and
tables about a library.

Basically this is my class diagram:

My goal is to check how hibernate handles inheritance. However when I'm trying to insert an author into my database I get the following error:

63 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.1.GA
110 [main] INFO org.hibernate.cfg.Environment - not found
125 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
156 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
391 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
391 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
953 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Author.hbm.xml
1281 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: Author -> authors
1375 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Book.hbm.xml
1485 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: Book -> books
1906 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Novel.hbm.xml
2031 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: Novel -> novels
2047 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Comic.hbm.xml
2141 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: Comic -> comics
2156 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
2172 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
2172 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 1
2188 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
2313 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost/TestHibernate
2313 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=postgres, password=****}
2641 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: PostgreSQL, version: 8.2.4
2641 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.3 JDBC4 with SSL (build 604)
2719 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.HSQLDialect
2735 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
2735 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2735 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
2735 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
2735 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
2735 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
2750 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
2750 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
2750 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
2766 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
2766 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
2766 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
2766 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
2766 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2766 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
2766 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
2766 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
2766 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
2781 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
2797 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
2797 [main] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.NoCacheProvider
Hibernate: call next value for authors_id_seq
2797 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
2797 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
2813 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
2813 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
2813 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
2813 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
2828 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
3047 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
3891 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
4360 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 42601
4375 [main] ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: syntax error at or near "call"
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not get next sequence value
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(
at org.hibernate.impl.SessionImpl.saveOrUpdate(
at org.hibernate.impl.SessionImpl.saveOrUpdate(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(
at $Proxy0.saveOrUpdate(Unknown Source)
at TestHibernate.main(
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "call"
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(
at org.postgresql.core.v3.QueryExecutorImpl.processResults(
at org.postgresql.core.v3.QueryExecutorImpl.execute(
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(
... 15 more

Since I'm a new child with Posgresql and Hibernate, I don't know where to head to solve my problem. I tried to log the queries made by Hibernate, but I got now luck.

Any ideas?




Samuel Cadieux
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah ha!

I've found my mistake (that I copy/pasted from a tutorial).

My problem was in the dialect specified in hibernate.cfg.xml. Basically Hibernate was trying to speak HSQL with Postgres.

So I changed:

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!