-->
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: Problem when using generator class sequence
PostPosted: Fri Sep 18, 2009 1:21 pm 
Newbie

Joined: Wed Sep 16, 2009 4:05 pm
Posts: 3
Hi,

I am new to hibernate and this is my second post here. I need help for using generator class "sequence" in primary key identifier mapping of my table. My confusion is, do I have to create the sequence I mention for parameter name manually in the database? As I was not sure, I have created my sequence manually. I think I am doing every thing as it is mentioned in the hibernate documentation but still I get following exception when I try to insert data in the table:

org.hibernate.exception.SQLGrammarException: could not get next sequence value
..
Caused by: org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequenc
e" does not exist
..

I have create following hibernate java bean:
public class Query implements Serializable {
private int queryId;
private String queryName;
...
}
Its hibernate mapping file Query.hbm.xml is as follows:
<?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 package="com.akazaresearch.phenonet.server.main.persist.hiber">
<class name="Query" table="runtime_build_query" >
<id name="queryId" column="id" >
<generator class="sequence">
<param name="sequence">runtime_build_query_queryid_seq</param>
</generator>
</id>
<property name="queryName" column="name" type="string"></property>
...
</hibernate-mapping>

Table script for postgres database is:
CREATE TABLE runtime_build_query
(
id integer NOT NULL,
userid integer NOT NULL,
name character varying(100) NOT NULL,
description character varying(200),
summary character varying(300),
approved boolean DEFAULT false,
complete boolean DEFAULT false,
finalized boolean DEFAULT false,
activated boolean DEFAULT true,
last_update_timestamp timestamp with time zone,
result_download_approved boolean DEFAULT false,
CONSTRAINT runtime_build_query_pkey PRIMARY KEY (id)
)
WITHOUT OIDS;
ALTER TABLE runtime_build_query OWNER TO chin;

I have created a sequence using following sql statement:
CREATE SEQUENCE runtime_build_query_queryid_seq INCREMENT BY 1 MINVALUE 1 NO MAXVALUE;

I don't know where I am going wrong. Please suggest. Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Problem when using generator class sequence
PostPosted: Fri Sep 18, 2009 3:45 pm 
Newbie

Joined: Wed Sep 16, 2009 4:05 pm
Posts: 3
Hi,

The problem I mentioned is solved. Actually earlier I had tried with "native" generator type which did not work because I had not created any sequence in my database. After changing it to "sequence" and creating the sequence manually, still I got the same error which I mentioned in last post. But it was probably a cache problem. When I re-deployed the application to tomcat server and started it from fresh again it did work. thanks.


Top
 Profile  
 
 Post subject: Re: Problem when using generator class sequence
PostPosted: Fri Sep 18, 2009 7:22 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quote:
CREATE SEQUENCE runtime_build_query_queryid_seq INCREMENT BY 1 MINVALUE 1 NO MAXVALUE;


Indeed, with this sequence created, everything should have been working. Cached code problems can indeed be frustrating!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.