-->
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.  [ 7 posts ] 
Author Message
 Post subject: Generator id database independent solution ?
PostPosted: Tue Sep 20, 2005 4:47 am 
Beginner
Beginner

Joined: Tue Sep 20, 2005 4:32 am
Posts: 29
Location: Cluj-Napoca
Is there a database independent solution for generating Id's for a table without changing the domain object when passing from one db to another ?

It works the solution with generator-class="native" ?

For the db's that uses sequences, the sequences will be created automatically ?


Top
 Profile  
 
 Post subject: Re: Generator id database independent solution ?
PostPosted: Tue Sep 20, 2005 5:02 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
crista wrote:
It works the solution with generator-class="native" ?

For the db's that uses sequences, the sequences will be created automatically ?

native is the solution you're looking for. But the sequence is not created automatically - I guess (haven't tried it yet, but this is the only way that makes sense) you must provide the sequence parameter:
Code:
<param name="sequence">Your sequence name here</param>

The parameter is only used if the database actually supports sequences.

Erik


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 5:27 am 
Beginner
Beginner

Joined: Tue Sep 20, 2005 4:32 am
Posts: 29
Location: Cluj-Napoca
As I understand from Hibernate documentation, if I set generator-class="native" it will pick for each db the "native" solution for generating id's, and for Oracle db for example it will pick "sequence".
If the sequences are not automatically created and you have to provide their name this is not an db independent solution.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 5:35 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
crista wrote:
If the sequences are not automatically created and you have to provide their name this is not an db independent solution.

I do not really agree with you. It actually depends what your expect when you hear: db independent solution.

I expect that my mapping works on different databases without changes. The fact that I have to define the name of the sequence for databases supporting sequences is OK for me: I don't expect (and even do not want) Hibernate to generate some sequence itself without "consulting" me - this would lead to endless problems (name conflicts etc.).

My humble opinion on the subject :-).

Erik


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 6:51 am 
Beginner
Beginner

Joined: Tue Sep 20, 2005 4:32 am
Posts: 29
Location: Cluj-Napoca
Erik, as you just said:
"I expect that my mapping works on different databases without changes."
is also my definition for database independent solution.
But if I use generator-class="native" like an such solution and I have to specify the sequence name, this is not an db independent solution because if I switch to another db I have to change the mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 7:05 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
crista wrote:
But if I use generator-class="native" like an such solution and I have to specify the sequence name, this is not an db independent solution because if I switch to another db I have to change the mapping.

I fail to understand where we disagree. I define
Code:
<param name="sequence">sq_x</param>

and then I know that on any database that supports sequences Hibernate will use sq_x to generate the id.

On a database supporting identity, it will ignore the sequence settings and generate the id using identity. So I can work on both type of databases without change to the mapping. That's how I understand db independence. It's a fact - and this is probably what you mean - that the mapping is not totally neutral and that Hibernate doesn't do all the work for us.

Maybe we should simply agree on the fact that we disagree :-), but it seems to be the way Hibernate supports db independence - though it doesn't deserve this name in your opinion.

Erik


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 2:57 am 
Beginner
Beginner

Joined: Tue Sep 20, 2005 4:32 am
Posts: 29
Location: Cluj-Napoca
That's Ok Erik.
I didn't know that what you said :
"On a database supporting identity, it will ignore the sequence settings and generate the id using identity" will function.
I thought that if I specify the name of the sequence on an db with identity I will get an error.

I have verified and that's working.

Thanks,
Cristian.


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