-->
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.  [ 6 posts ] 
Author Message
 Post subject: GenerationType.AUTO gives 1 sequence for all tables
PostPosted: Tue Apr 29, 2008 8:38 am 
Newbie

Joined: Tue Apr 29, 2008 3:02 am
Posts: 5
Hibernate version: 3.2.6.GA
Mapping documents:none -> using Annotations
Code between sessionFactory.openSession() and session.close():everything fine here
Full stack trace of any exception that occurs:no error no exception
Name and version of the database you are using:PostgreSQL 8.3

I have a small test project in Hibernate to learn the basics. I make use of Annotations and i want to autogenerate the ids of 4 tables with:
Code:
@GeneratedValue(strategy=GenerationType.AUTO)

That works fine in MySQL but creates only 1 sequence in PostgreSQL with the following effect:

enter object1 of type 1 --> ID 1
enter object2 of type 2 --> ID 2 (and not 1 as expected)
enter object3 of type 3 --> ID 3 (and not 1 as expected)
enter object4 of type 1 --> ID 4 (instead of 2)

I also tried own sequence generators which worked fine for Postgre but didn't work in MySQL (since there are no sequences in MySQL). I want to keep the whole project as generic as possible. Are there any tricks for using the
Quote:
GenerationType.AUTO
with PostgreSQL

Thx in advance[/b]

_________________
Rechtschreibfehler sind beabsichtigt und dienen der allgemeinen Erheiterung.


Top
 Profile  
 
 Post subject: questions
PostPosted: Tue Apr 29, 2008 5:59 pm 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
Try investigating GenetationType.TABLE?
Also, maybe the examples in the following URL will prove useful:

http://edocs.bea.com/kodo/docs41/full/html/ejb3_overview_mapping_sequence.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 3:40 am 
Newbie

Joined: Tue Apr 29, 2008 3:02 am
Posts: 5
Hi sagimann,

i changed to
Code:
GenerationType.TABLE
and it works fine with both databases.
Is it possible to force Hibernate to pick up the next value after a server restart?
Right now he grabs a number starting at +50 or less.
lastID 3 -> restart -> nextID 50
lastID 86 -> restart -> nextID 100
lastID 101 -> restart -> nextID 150
This is not really a problem. I'm just curious whether it is possible.

Thx a lot already for the tip.
What i've seen so far is really cool. Hibernate rocks!!!

_________________
Rechtschreibfehler sind beabsichtigt und dienen der allgemeinen Erheiterung.


Top
 Profile  
 
 Post subject: suggestion
PostPosted: Wed Apr 30, 2008 5:00 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
try changing allocation-size, which defaults to 50 I think.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 5:24 am 
Newbie

Joined: Tue Apr 29, 2008 3:02 am
Posts: 5
That worked like a charm. Thanks a lot again. Is there a special reason why it is set to 50 initially?

Greetings

_________________
Rechtschreibfehler sind beabsichtigt und dienen der allgemeinen Erheiterung.


Top
 Profile  
 
 Post subject: guessing..
PostPosted: Wed Apr 30, 2008 5:31 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
Not sure. For me, it's just a good indication that the server went down (in case it was unexpected), although there are usually far better indications like logs, etc.


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