-->
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: Auto increment a column that is not a key
PostPosted: Sat Oct 07, 2006 10:07 am 
Beginner
Beginner

Joined: Thu Jun 02, 2005 9:36 am
Posts: 20
I can't seem to find an easy way to have an arbitrary column be auto incremented. It's not the primary key, not the identity, just a normal column and I want it to auto increment. How can this be done?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 07, 2006 10:48 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
Jshellman,

Do you want this arbitrary column to be autoincremented for each new record or once every record is saved?

For the former case you can just leave this to the database engine. For the latter you can use a hibernate version tag.
http://www.hibernate.org/hib_docs/v3/re ... on-version

Add some more details if I misunderstood your question :)

Marius


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 12, 2007 10:52 am 
Newbie

Joined: Thu Jan 11, 2007 1:57 pm
Posts: 9
hi!

i have the same plroblem. i have an entity with a embedded primary key. this entity should have also a "counter". just a normal field defined with autoincrement. The auto increment should be 100000000. The Table created by hibernate should looks like:

CREATE TABLE PAYMENTTRANSACTION ( .... (other column definitions)...,
invoicenumber INT(9) NOT NULL AUTO_INCREMENT KEY) AUTO_INCREMENT = 100000000;

any new persisted entity should have the field invoicenumber with the autoincremented value. Something like this:

UUID | .... | INVOICENR |
ac7317a0-788c-11db-9fe1-0800200c9a66| .... | 100000001 |
ac7317a0-788c-11db-9fe1-0800200c9a67| .... | 100000002 |
ac7317a0-788c-11db-9fe1-0800200c9a68| .... | 100000003 |
ac7317a0-788c-11db-9fe1-0800200c9a69| .... | 100000004 |

could somebody help me?

i tried things like @Version, @Generated, @GeneratedValue, etc. but it does not work :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 2:38 pm 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
Well this may help you or not ;-)
http://forum.hibernate.org/viewtopic.ph ... highlight=

I'm still searching for a solution that will consider the IP address so my visits are unique.


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.