Announcement Announcement Module
Collapse
No announcement yet.
Bad SQL grammar in task Hibernate operation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bad SQL grammar in task Hibernate operation

    When connecting to my webapp, I receive the following error message: Bad SQL grammar [] in task 'Hibernate operation'; nested exception is org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist

    The hbm.xml file:
    <hibernate-mapping auto-import="true">

    <class name="org.myspring.Person" table="T_Person">
    <id name="id" column="id" unsaved-value="-1">
    <generator class="sequence"/>
    </id>
    <property name="firstName" column="firstName"/>
    <property name="lastName" column="lastName"/>
    </class>

    </hibernate-mapping>


    Database:

    CREATE TABLE "T_Person"
    (
    id varchar(10) NOT NULL,
    "firstName" varchar(20),
    "lastName" varchar(30) NOT NULL,
    CONSTRAINT "PK_T_Person" PRIMARY KEY (id)
    )
    WITHOUT OIDS;


    Stacktrace:
    org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [] in task 'Hibernate operation'; nested exception is org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist at org.postgresql.util.PSQLException.parseServerError (PSQLException.java:139) at org.postgresql.core.QueryExecutor.executeV3(QueryE xecutor.java:152) at org.postgresql.core.QueryExecutor.execute(QueryExe cutor.java:100) at org.postgresql.core.QueryExecutor.execute(QueryExe cutor.java:43) at org.postgresql.jdbc1.AbstractJdbc1Statement.execut e(AbstractJdbc1Statement.java:517) at org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(AbstractJdbc2Statement.java:50) at org.postgresql.jdbc1.AbstractJdbc1Statement.execut eQuery(AbstractJdbc1Statement.java:233) at net.sf.hibernate.id.SequenceGenerator.generate(Seq uenceGenerator.java:69) at net.sf.hibernate.impl.SessionImpl.saveWithGenerate dIdentifier(SessionImpl.java:765) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl .java:738) at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(Ses sionImpl.java:1388) at org.springframework.orm.hibernate.HibernateTemplat e$13.doInHibernate(HibernateTemplate.java:320) at org.springframework.orm.hibernate.HibernateTemplat e.execute(HibernateTemplate.java:176) at org.springframework.orm.hibernate.HibernateTemplat e.saveOrUpdate(HibernateTemplate.java:317) at
    ...


    Questions:
    • How can I verify the sql statements that have been generated automagically?
      Should I add a hibernate_sequence relation in my database? If yes, how do I define this relation?

    Thanks for any help regarding this issue.

  • #2
    Hibernate sequence generator for postgresql takes a parameter that is the sequence name:
    Code:
    <generator class="sequence">
       <param name="sequence">sequence_name</param>
    </generator>
    by default, Hibernate uses hibernate_sequence. You can create it using:
    Code:
      create sequence hibernate_sequence;
    How can I verify the sql statements that have been generated automagically?
    Add the following line to your LocalSessionFactoryBean definition in applicationContext:
    Code:
    <prop key="hibernate.show_sql">true</prop>
    HTH

    Comment


    • #3
      Originally posted by irbouho
      Hibernate sequence generator for postgresql takes a parameter that is the sequence name. By default, Hibernate uses hibernate_sequence.
      Applying the proposed solution solved my problem. Thank you

      Comment

      Working...
      X