-->
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: getting next value of sequence
PostPosted: Mon Jun 08, 2009 8:22 am 
Regular
Regular

Joined: Fri May 22, 2009 4:50 am
Posts: 59
hi,

I want to use next value of a sequence so that i can assign this value to an attribute in my object before persisting it in database.
I can't use <generator class="sequence"> as this attribute is not the primary key for my table and i am already using <generator class="uuid"> uuid for the same table.
When i create my HQL query using DUAL it gives me an exception saying that DUAL is not mapped.

Kindly help me with this problem.
Thanks in advance.


Top
 Profile  
 
 Post subject: Re: getting next value of sequence
PostPosted: Mon Jun 08, 2009 8:29 am 
Beginner
Beginner

Joined: Mon Jun 01, 2009 5:39 am
Posts: 34
Hibernate will generate the sequence number for you at insert time, you don't even need to worry about that.


Top
 Profile  
 
 Post subject: Re: getting next value of sequence
PostPosted: Mon Jun 08, 2009 8:44 am 
Regular
Regular

Joined: Fri May 22, 2009 4:50 am
Posts: 59
Kindly elaborate more.

I didnt get how hibernate can link a sequence to my attribute? just to mention again, i am not using <generator class="sequence"> as this attribute is not my primary key.

Besically i have two coloumns in my table.
One is uuid which gets generated by hibernate using <generator class="uuid">
and other one is hrid which i want to be sequential.

Now I dont know how to use sequence to generate values for hrid.
Knidly suugest some solution.

Thanks


Top
 Profile  
 
 Post subject: Re: getting next value of sequence
PostPosted: Mon Jun 08, 2009 9:04 am 
Beginner
Beginner

Joined: Mon Jun 01, 2009 5:39 am
Posts: 34
OK, sorry, I misread... According to:

http://docs.jboss.org/hibernate/stable/ ... rated.html

and:

http://docs.jboss.org/hibernate/stable/ ... n-property

Hibernate will, in fact, not generate the sequence for you. It only does so for primary keys, which is curious.


Top
 Profile  
 
 Post subject: Re: getting next value of sequence
PostPosted: Mon Jun 08, 2009 9:31 am 
Regular
Regular

Joined: Fri May 22, 2009 4:50 am
Posts: 59
True.
Basically i am looking for HQL equilvalent of this SQL query now..
"select main_sequence.NEXTVAL from DUAL"

Any idea?

Thanks


Top
 Profile  
 
 Post subject: Re: getting next value of sequence
PostPosted: Mon Jun 08, 2009 12:04 pm 
Regular
Regular

Joined: Fri May 22, 2009 4:50 am
Posts: 59
i am running SQL query instead of HQL to generate nextval, updating my object with it and then persisting using hibernate.
It work for me! :)


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.