-->
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.  [ 9 posts ] 
Author Message
 Post subject: PostgreSql sequence does not see to work for me
PostPosted: Thu Jul 21, 2005 1:42 pm 
PostgreSql sequence does not see to work for me. If I change it to increment it works fine. According to the manual (Basic O/R Mapping chapter 3) I should use sequence. Does anyone have any insight on this?
Here is my mapping file. And of course my code section. If that is any help.

Thanks ray lukas


MY MAPPING FILE ------------------------

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
     
     
<hibernate-mapping package="busObjs">
   <class name="Kpis" table="kpis" >
      <id name="id" type="java.lang.Long" column="id" >
           <generator class="[b]sequence[/b]"/>
      </id>

      <property name="name"
                                               column="name"
                                               type="string"
                                               not-null="true"  />
      <property name="ownersName"
                                               column="owner_name"
                                               type="string"
                                               not-null="true" />
      <property name="objectiveID"
                                               column="objective_id"
                                               type="java.lang.Long"
                                               not-null="true" />
      <property name="measureID"
                                               column="measure_id"
                                               type="java.lang.Long"
                                               not-null="true" />
   </class>   
</hibernate-mapping>



MY CODE ---------------------
Code:
private void createTest() {
      KpisDAO kpisDao = new KpisDAO();
      Kpis kpis = new Kpis ();
      kpis.setMeasureID(new Long(100));
      kpis.setName("Test kpis from measure");
      kpis.setObjectiveID(new Long(200));
      kpis.setOwnersName("test owner name");
      kpisDao.save(kpis);
   }


Top
  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 3:11 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
can't quite remember what I used on my own test project, but try native... failing that, try identity. I am, of course, assuming your database table has been set up with an auto-generated id.


Top
 Profile  
 
 Post subject: clearly spec'd out in manual, Increment does work, but
PostPosted: Thu Jul 21, 2005 3:48 pm 
well ...

I am using increment right now and it works just great, although the manual says not to use it in clusters. Not sure we are going to need to. I am just not sure..

The database table is set for NO Auto Increment.. I did that because I want Hibernate to control the auto-incrementing and not the database. You know I don't want them to collide or have confusion.

I think that this would happen since Hibernate would generate an id and then pass it to the database which is also trying to generate one. Humm did not seem like the thing to do.

As I mentioned, on page 53 of the Hibernate manual, chapter 3.. "Sequence" is specified for PostgreSql. "identity" is specified for DB2, MySql, SQL Server, and Hypersonice SQL.


Top
  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 5:58 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
Quote:
The database table is set for NO Auto Increment.. I did that because I want Hibernate to control the auto-incrementing and not the database. You know I don't want them to collide or have confusion.

If you are using a native generator type (either identity or sequence), there will be no confusion. Hibernate will rely on the database to generate the id for it. That said, increment will work fine, as you say, if you are not working in a cluster, and no other application will be inserting data into the mapped table.

Quote:
As I mentioned, on page 53 of the Hibernate manual, chapter 3.. "Sequence" is specified for PostgreSql. "identity" is specified for DB2, MySql, SQL Server, and Hypersonice SQL.

Right, all I am saying is that when I set up a test schema (a Person to Address mapping, with Person.id generated by PostgreSQL), I had to use identity. sequence gave me errors. In particular, my table is defined as:

Code:
CREATE TABLE person
(
  per_id serial NOT NULL,
  per_first_name varchar(40) NOT NULL,
  per_last_name varchar(40) NOT NULL,
  per_weight_kg numeric(4,2),
  per_height_m numeric(4,2),
  per_birth_date date
)


and when I session.save(new Person(...)) with sequence, I get this:

Code:
ERROR [main] - ERROR: relation "hibernate_sequence" does not exist
org.hibernate.exception.SQLGrammarException: could not get next sequence value
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
   at ...

same with native. Identity, however, works fine. This very well may have to do with my schema and how I created my tables (I used pgAdmin III), or even possibly to do with the version: Win32 build of PostgreSQL 8.0).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 6:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
In HB3 both "sequence" and "identity" work on postgres. "native" means the same as "identity". Of course, if you use "sequence", you must make sure there is actually a sequence in the database with the name you specify!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 6:47 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
Quote:
"native" means the same as "identity"

Strange... then why do I get the same error with native as I do with sequence?

(personally, I prefer identity to sequence anyway for most stuff, anyway)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 9:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Depends on the database. On Oracle "native"= sequence on MSSQL "native" = identity etc etc


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 9:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Excuse me. I said wrong.

On PostgreSQLDialect:

Code:
   public Class getNativeIdentifierGeneratorClass() {
      return SequenceGenerator.class;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 9:49 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
gavin wrote:
Excuse me. I said wrong.

On PostgreSQLDialect:

Code:
   public Class getNativeIdentifierGeneratorClass() {
      return SequenceGenerator.class;
   }


Oh, okay. Thanks for the clarification, Gavin.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.