-->
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.  [ 4 posts ] 
Author Message
 Post subject: Autoincrement on fileds or properties
PostPosted: Thu Jun 03, 2004 6:37 am 
Newbie

Joined: Thu Jun 03, 2004 6:27 am
Posts: 2
Hi,

I'm rewriting our application to use Hibernate and thus replacing OJB. The process has been very smooth and I've got just one problem to solve.

In one of our tables (ORDERREQ) we have a uuid generated primarykey but also an autoincremented field called ordernr. In OJB I defined this as:
<class-descriptor
class="OrderReq"
table="ORDERREQ"
>
<field-descriptor
name="id"
column="ID"
jdbc-type="VARCHAR"
primarykey="true"
/>
<field-descriptor
name="orderNr"
column="ORDERNR"
jdbc-type="BIGINT"
autoincrement="true"
/>

As you can see the field orderNr is not a primary key but OJB supports autoincrementing it anyway. I've searched this forum and read the manual for Hibernate but couldn't find anything that will manipulate fields. This is part of my definition of OrderReq in Hibernate:

<hibernate-mapping>
<!-- com.printondirect.vo.OrderReq root -->
<class name="com.printondirect.vo.OrderReq" table="OrderReq">

<id name="id" type="string" column="id">
<generator class="assigned"/>
</id>

<property name="orderStatus" column="orderStatus" type="int"/>
<property name="campaignDiscount" column="campaignDiscount" type="double"/>
<property name="orderedDate" column="orderedDate" type="date"/>
<property name="deliveryTime" column="deliveryTime" type="int"/>
<property name="paymentMethod" column="paymentMethod" type="int"/>
<property name="referrer" column="referrer" type="string"/>
<property name="orderNr" column="orderNr" type="long"/>
<property name="password" column="password" type="string"/>

My question is if it possible to make Hibernate autoincrement my field orderNr or can I somehow write my own incrementor doing this? It's way too much work to rewrite the application to use ordernr as primary key so that's not really an option.

Using DB2 v. 7.1.7, Hibernate 2.1.3, WebSphere 5

Thanks for any help or suggestions!

/Emil


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 7:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The property is autoincremented by the database? If yes, just use insert=false on the property.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 8:06 am 
Newbie

Joined: Thu Jun 03, 2004 6:27 am
Posts: 2
The property is not autoincremented by the database, DB2 v. 7 doesn't support this! So I'm still in a bit of a fix - any more ideas?

/Emil


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 8:08 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Usually, you create a sequence in the database and use it as a default value for that column, e.g. default "seq.nextid".

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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