facebook

[Closed] Another Noob: Spring/Hibernate/PostgreSQL

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #254500 Reply

    Paul
    Participant

    I followed the posts in this thread (http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-13177.html) and though similiar, ultimately didn’t find a solution.

    I’m on Linux, fresh install of Eclipse 3.2, ME 5.0M2, Postgres 8.0.

    I have a table customer, and using DB Explorer I generated a Hibernate mapping. The table DDL is:

    
        create table "public"."customer"(
            "id"  serial not null,
           "firstname" varchar(75),
           "lastname" varchar(75),
           "address1" varchar(75),
           "address2" varchar(75),
           "city" varchar(75),
           "state" varchar(75),
           "country" varchar(75),
           "postal" varchar(15),
           "homephone" varchar(15),
           "cellphone" varchar(15),
           "emailaddress" varchar(100),
           "workphone" varchar(15),
            constraint "customer_id" primary key ("id")
        );
    
        create unique index "customer_id" on "public"."customer"("id");

    At the ID Generator on Page 2 of the mapping wizard, I chose ‘native’ as the ID column is of type serial in Postgres (this is the difference from the referenced thread).

    The generated Customer.hbm.xml file has this for the id column:

    <id name="id" type="java.lang.Integer">
                <column name="id" />
                <generator class="native"></generator>
    </id>

    I run the web application, and I can read data just fine. Inserting a new record though results in the following error:

    org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not get next sequence value; bad SQL grammar [select nextval ('hibernate_sequence')]; nested exception is java.sql.SQLException: ERROR: relation "hibernate_sequence" does not exist
        org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:223)
        org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
        org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:411)
        org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:370)
        org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:612)
        com.nwnetsolutions.data.CustomerDAO.save(CustomerDAO.java:42)
        com.nwnetsolutions.controllers.web.IndexController.onSubmit(IndexController.java:36)
        org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:258)
        org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:259)
        org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:139)
        org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:717)
        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:658)
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:392)
        org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:357)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
        com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)

    The generated SQL was:

    Hibernate: select customer0_.id as id, customer0_.firstname as firstname0_, customer0_.lastname as lastname0_, customer0_.address1 as address4_0_, customer0_.address2 as address5_0_, customer0_.city as city0_, customer0_.state as state0_, customer0_.country as country0_, customer0_.postal as postal0_, customer0_.homephone as homephone0_, customer0_.cellphone as cellphone0_, customer0_.emailaddress as emailad12_0_, customer0_.workphone as workphone0_ from public.customer customer0_
    Hibernate: select nextval ('hibernate_sequence')

    Where is the reference to “hibernate_sequence” coming from, and how do I correct this (I’m assuming this is my problem)? As I understand it Postgres is supposed to work using a ‘native’ generator w/ a serial column.

    I’ve googled and not found much reference to this error, so I’m not sure if it’s a generation issue w/ MyEclipse, something I’m doing wrong, etc. Any help appreciated, thanks.

    #254504 Reply

    Haris Peco
    Member

    pwoods,

    For postgresql seraial/bigserial you have to choose identity generator

    best regards

    #254553 Reply

    Paul
    Participant

    That worked, thanks. I finally saw in the referenced thread where you said the same thing.

    My confusion I think came from reading this earlier (http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html) where they say “For cross-platform development, the native strategy will choose from the identity, sequence and hilo strategies, dependant upon the capabilities of the underlying database.”

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: [Closed] Another Noob: Spring/Hibernate/PostgreSQL

You must be logged in to post in the forum log in