-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Add first item to a postgresql table
PostPosted: Fri Dec 08, 2006 7:08 pm 
Newbie

Joined: Tue Nov 14, 2006 5:50 pm
Posts: 3
Im using hibernate 3.2 with postgresql 8.1.

I have an Employee class, and I am trying to save the very first employee to the table

session = factory.openSession();
session.beginTransaction();
session.save(this);
session.getTransaction().commit();

I get this error:

Hibernate: select nextval ('hibernate_sequence')
org.hibernate.exception.SQLGrammarException: could not get next sequence value
...
Caused by: org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist

I created the table by hand like this:
create table employee (id serial primary key, lastName varchar(40), firstName varchar(40));

Do I somehow need to create the schema from hibernate?

I appreciate any suggestions!

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.schumeyer.trust.Employee" table="EMPLOYEE">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="lastName" />
<property name="firstName" />
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 09, 2006 4:51 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Since you are using the "Native" Generator for the generation of your primary key hibernate tries to load the id from a sequence called hibernate_sequence.

Basically you have two options:
- if you don't want to use hibernate_sequence you have to look for a different id generator. This is documented here:
http://www.hibernate.org/hib_docs/v3/re ... aration-id

- The easiest solution for you would be to create the hibernate_sequence in Postgres like that:
Code:
CREATE SEQUENCE hibernate_sequence

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 09, 2006 11:01 am 
Newbie

Joined: Tue Nov 14, 2006 5:50 pm
Posts: 3
After some digging, I changed the mapping to add the param element. This seems to work.

<class name="com.schumeyer.trust.Employee" table="EMPLOYEE">
<id name="id" type="integer" column="id">
<generator class="native">
<param name="sequence">employee_id_seq</param>
</generator>
</id>
<property name="lastName" />
<property name="firstName" />
</class>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.