-->
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.  [ 5 posts ] 
Author Message
 Post subject: Native SQL that doesn't return a hibernate object
PostPosted: Fri Sep 02, 2005 3:21 am 
Newbie

Joined: Fri Sep 02, 2005 3:00 am
Posts: 2
I have a piece of Oracle SQL that returns me the next available sequence number. How do I execute this in Hibernate? The object I want to return (String), is NOT any of my Hibernate objects, but all the methods I can find to execute SQL apparently must return a Hibernate object.

The SQL I want to execute is this:
select transaction_seq.nextval from dual

To create the sequence I used:
CREATE SEQUENCE transaction_seq
MINVALUE 1
MAXVALUE 999999999999999999999999999
START WITH 1
INCREMENT BY 1
CACHE 20

Regards
b


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 3:52 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Use plain JDBC with Hibernate's connection.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 3:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
or use <return-scalar> with H3

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Explain please
PostPosted: Fri Sep 02, 2005 4:13 am 
Newbie

Joined: Fri Sep 02, 2005 3:00 am
Posts: 2
Thanks for the replies. Max, unfortunately I'm using H2. :( Alesj (or Max), could you please explain how to use JDBC with H2?

I changed my dialect to net.sf.hibernate.dialect.GenericDialect, which I would assume would use the default JDBC drivers, but that didn't solve my problem.

The Java code I am trying to execute, but which fails, is this:
List seqNo = getSession()
.createQuery("select transaction_seq.nextval from dual")
.list();
return (String)seqNo.get(0);

The dialect is this:
net.sf.hibernate.dialect.GenericDialect

But I also tried and failed with:
net.sf.hibernate.dialect.Oracle9Dialect

Thanks guys
b


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 4:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the dialect should match your database.

using raw jdbc is just done by getting the connection from the session.
session.connect()

_________________
Max
Don't forget to rate


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