-->
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.  [ 8 posts ] 
Author Message
 Post subject: id generator
PostPosted: Wed Jul 07, 2004 5:31 am 
Newbie

Joined: Fri Jul 02, 2004 5:20 am
Posts: 8
Location: Montpellier France
Hello everybody,


I'm working with an Oracle 8 database which provides sequences to create unique primary key.

I have a POJO class "AideFinanciere" with a String type identifier field "aideCode" mapped to a VARCHAR2 column. I would like to use the sequence id generator of the database by declaring in my mapping :

(1)
<generator class="sequence">
<param name="sequence">seq#24</param>
</generator>


The problem is that the sequence generator returns a long value and that the id property is a String (it throws an exception "this generator returns a long, int, short"). I can't change the database column type because another application is working with it.

The other application retrieve these sequences numbers using to_char () with SQL request :

(2)
select to_char(seq#24.nextval) from sys.dual

But I don't know how to write a query for a sequence using Hibernate.

Does anybody knows how to access to a sequence next value with an HQL request or a trick to cast the long id generated by the hibernate generator to a String?

Thanks,
Eric

hibernate version : 2.1


[color=olive]the exception in case (1) :

DEBUG [http8080-Processor2] (AideFinanciereBO.java:53) - numSequence : 24
DEBUG [http8080-Processor2] (AideFinanciereDAOHibernateImpl.java:95) - AideFinanciereDAOHibernateImpl : insertion aide financi

_________________
----------------------
Eric Manuguerra


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 6:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Just write your own generator extending or similar to SequenceGenerator. Should not be too difficult.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 8:33 am 
Newbie

Joined: Fri Jul 02, 2004 5:20 am
Posts: 8
Location: Montpellier France
Thank tou for your reply,

Tell me if I've understood you right :

I'm gonna change the generator to "assigned"

write a public String getSequenceNextValue(String sequenceName) method in SeqDAO

In that method I will instantiate a SequenceGenerator

configure it :

configure(Type type, Properties params, Dialect dialect)

and then generate the identifier :

generate(SessionImplementor session, Object obj)

and take the String.valueOf() the generated identifier
to return it.

Is that correct?

But how to configure the Sequence generator? What arguments should I pass to the configure and generate methods?

If you can help me ,thanks

_________________
----------------------
Eric Manuguerra


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 11:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No.

You write a class that extends net.sf.hibernate.id.SequenceGenerator, which ovverrides generate() and does return super.generate().toString() or something. Then you use

<id ...>
<generator class="yourclassname">
</id>

Just look at the source of other generators to get an idea of how it works.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 08, 2004 8:54 am 
Newbie

Joined: Fri Jul 02, 2004 5:20 am
Posts: 8
Location: Montpellier France
Hello Micha

_________________
----------------------
Eric Manuguerra


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 10:31 am 
Newbie

Joined: Fri Jul 02, 2004 5:20 am
Posts: 8
Location: Montpellier France
Hello Micha

_________________
----------------------
Eric Manuguerra


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 10:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Nice that you got this solved. And thanks for posting the solution.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 10:17 am 
Newbie

Joined: Mon Aug 23, 2004 7:54 am
Posts: 15
How is this the right solution? sql member is private in SequenceGenerator


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