• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 - hibernate.properties 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(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:119)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:534)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:526)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:522)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)
at $Proxy0.saveOrUpdate(Unknown Source)
at TestHibernate.main(TestHibernate.java:13)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "call"
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1608)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1343)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:194)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:98)
... 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?

SQL


hibernate.cfg.xml


Author.hbm.xml


TestHibernate.java


Author.java

 
Samuel Cadieux
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:


To:
 
reply
    Bookmark Topic Watch Topic
  • New Topic