Обсуждение: What Hibernate Object ID generator is recommanded for PG?

Поиск
Список
Период
Сортировка

What Hibernate Object ID generator is recommanded for PG?

От
Vernon
Дата:
Hi,

Here is what I have:

Java class:

public class User {

    private Integer id;
...
}

Hibernate Mapping:

    <class name="com.ccc.domain.User" table="users">
        <id name="id" type="int" unsaved-value="null"
>
            <generator class="native"/>
        </id>
...
    </class>

DB Table:

create table USERS (
    id             SERIAL UNIQUE primary key,
...
)

When I call the save(object) method of Hibernate, I
get the following exception:

2005-04-21 13:52:13,859 ERROR
org.springframework.web.servlet.DispatcherServlet -
Could not complete request
org.springframework.jdbc.BadSqlGrammarException: Bad
SQL grammar [] in task 'Hibernate operation'; nested
exception is java.sql.SQLException: ERROR: relation
"hibernate_sequence" does not exist
java.sql.SQLException: ERROR: relation
"hibernate_sequence" does not exist
    at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1365)
    at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1160)
    at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:172)
    at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:387)
    at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:328)
    at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:238)
    at
org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
    at
net.sf.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:64)
    at
net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:774)
    at
net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747)
    at
org.springframework.orm.hibernate.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:386)
    at
org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:243)
    at
org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:383)

It seems the native ID generator doesn't work properly
in PG. After changing the generator to sequence. I get
the same exception. According to the Hibernate
documentation, that is the right way. Any suggestions
on the subject?

Thanks,

Vernon

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Re: What Hibernate Object ID generator is recommanded for

От
Oliver Jowett
Дата:
Vernon wrote:

> It seems the native ID generator doesn't work properly
> in PG. After changing the generator to sequence. I get
> the same exception. According to the Hibernate
> documentation, that is the right way. Any suggestions
> on the subject?

You should probably ask on the Hibernate lists about this.

-O

Re: What Hibernate Object ID generator is recommanded for

От
Dave Cramer
Дата:
Vernon,

You need to create a sequence called hibernate_sequence

create sequence hibernate_sequence;

Dave
Vernon wrote:

>Hi,
>
>Here is what I have:
>
>Java class:
>
>public class User {
>
>    private Integer id;
>...
>}
>
>Hibernate Mapping:
>
>    <class name="com.ccc.domain.User" table="users">
>        <id name="id" type="int" unsaved-value="null"
>
>
>            <generator class="native"/>
>        </id>
>...
>    </class>
>
>DB Table:
>
>create table USERS (
>    id             SERIAL UNIQUE primary key,
>...
>)
>
>When I call the save(object) method of Hibernate, I
>get the following exception:
>
>2005-04-21 13:52:13,859 ERROR
>org.springframework.web.servlet.DispatcherServlet -
>Could not complete request
>org.springframework.jdbc.BadSqlGrammarException: Bad
>SQL grammar [] in task 'Hibernate operation'; nested
>exception is java.sql.SQLException: ERROR: relation
>"hibernate_sequence" does not exist
>java.sql.SQLException: ERROR: relation
>"hibernate_sequence" does not exist
>    at
>org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1365)
>    at
>org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1160)
>    at
>org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:172)
>    at
>org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:387)
>    at
>org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:328)
>    at
>org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:238)
>    at
>org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
>    at
>net.sf.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:64)
>    at
>net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:774)
>    at
>net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747)
>    at
>org.springframework.orm.hibernate.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:386)
>    at
>org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:243)
>    at
>org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:383)
>
>It seems the native ID generator doesn't work properly
>in PG. After changing the generator to sequence. I get
>the same exception. According to the Hibernate
>documentation, that is the right way. Any suggestions
>on the subject?
>
>Thanks,
>
>Vernon
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around
>http://mail.yahoo.com
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
>
>
>

--
Dave Cramer
http://www.postgresintl.com
519 939 0336
ICQ#14675561


Re: What Hibernate Object ID generator is recommanded for

От
"Xavier Poinsard"
Дата:
Use

    <generator class="native">
    <param name="sequence">YourSequence</param>
    </generator>

and, of course, create a sequence named YourSequence.


Vernon wrote:
> Hi,
>
> Here is what I have:
>
> Java class:
>
> public class User {
>
>     private Integer id;
> ...
> }
>
> Hibernate Mapping:
>
>     <class name="com.ccc.domain.User" table="users">
>         <id name="id" type="int" unsaved-value="null"
>
>             <generator class="native"/>
>         </id>
> ...
>     </class>
>
> DB Table:
>
> create table USERS (
>     id             SERIAL UNIQUE primary key,
> ...
> )
>
> When I call the save(object) method of Hibernate, I
> get the following exception:
>
> 2005-04-21 13:52:13,859 ERROR
> org.springframework.web.servlet.DispatcherServlet -
> Could not complete request
> org.springframework.jdbc.BadSqlGrammarException: Bad
> SQL grammar [] in task 'Hibernate operation'; nested
> exception is java.sql.SQLException: ERROR: relation
> "hibernate_sequence" does not exist
> java.sql.SQLException: ERROR: relation
> "hibernate_sequence" does not exist
>     at
> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1365)
>     at
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1160)
>     at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:172)
>     at
> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:387)
>     at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:328)
>     at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:238)
>     at
> org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
>     at
> net.sf.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:64)
>     at
> net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:774)
>     at
> net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747)
>     at
> org.springframework.orm.hibernate.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:386)
>     at
> org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:243)
>     at
> org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:383)
>
> It seems the native ID generator doesn't work properly
> in PG. After changing the generator to sequence. I get
> the same exception. According to the Hibernate
> documentation, that is the right way. Any suggestions
> on the subject?
>
> Thanks,
>
> Vernon
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>