-->
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: ID with generator "sequence" results in "int4
PostPosted: Thu Mar 10, 2005 10:19 am 
Newbie

Joined: Thu Mar 10, 2005 10:11 am
Posts: 3
I have a set of Java source files for which the hbm files are generated by XDoclet. All files are then packaged in a HAR file which is deployed on a JBoss Application Server and the DDL schema is automatically exported to a PostgreSQL 8.0 database server.

The following code is a sample from one of the Java sources:

Code:
    /**
     *            @hibernate.id
     *             generator-class="sequence"
     *             type="java.lang.Integer"
     *             column="user_role_id"
     *             unsaved-value="0"
     *
     *            @hibernate.generator-param
     *             name="sequence"
     *             value="UserRole"
     *         
     */
    public Integer getUserRoleId() {
        return this.userRoleId;
    }


This is the corresponding part from the generated hbm file:

Code:
        <id
            name="userRoleId"
            column="user_role_id"
            type="java.lang.Integer"
            unsaved-value="0"
        >
            <generator class="sequence">
                <param name="sequence">UserRole</param>
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-UserRole.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>


The problem is that the column "user_role_id" is defined as a simple int4 column on my PostgreSQL server, with no default value (which should be something like "nextval('UserRole')" ). All the sequence objects are properly generated in the database, they are just not used in the ID columns.

Can anyone help me?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 10, 2005 2:54 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Quote:
The problem is that the column "user_role_id" is defined as a simple int4 column on my PostgreSQL server, with no default value


Are you actually experiencing a problem or just anticipating it?

Hibernate will handle the select from the sequence when inserting. int4 is the equivalent mapping for an integer on postgres.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 10, 2005 5:45 pm 
Newbie

Joined: Thu Mar 10, 2005 10:11 am
Posts: 3
drj wrote:
Quote:
The problem is that the column "user_role_id" is defined as a simple int4 column on my PostgreSQL server, with no default value


Are you actually experiencing a problem or just anticipating it?

Hibernate will handle the select from the sequence when inserting. int4 is the equivalent mapping for an integer on postgres.

Yes, you're right, Hibernate manages the IDs correctly.

It's just that I'd want to have the ID auto-generated for me even if I interacted with the database differently, for example through pgadmin. Now I have to explicitly insert nextval('seq') into the ID column.

So this is not a bug :) .


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.