-->
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.  [ 3 posts ] 
Author Message
 Post subject: Oracle SequenceNextValString in Hibernate
PostPosted: Fri Apr 01, 2005 4:26 am 
Newbie

Joined: Fri Feb 04, 2005 9:45 am
Posts: 8
Location: Czech Republic
Hibernate version:2.6


Hi all,

Is Hibernate able to execute "native sql querry" without including class of querying table ( I mean if you want to execute query upon system table)? My goal was to execute SequenceNextVal upon the oracle database and increase the number.

Using this code, I can get the select.
Code:
prop.setProperty("hibernate.dialect", "net.sf.hibernate.dialect.Oracle9Dialect");
Dialect dialec = Dialect.getDialect(prop);
String nextvalString = dialec.getSequenceNextValString("SEQSIGNAT");


Response is:

select SEQSIGNAT.nextval from dual




Solution I made is mixing hibernate with JDBC.
Here is the whle code I use

Code:
Properties prop = new Properties();
prop.setProperty("hibernate.dialect", "net.sf.hibernate.dialect.Oracle9Dialect");
Dialect dialec = Dialect.getDialect(prop);

Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@..something...";
Connection con = DriverManager.getConnection(url, "user", "password");
Statement stmt = con.createStatement();

String nextvalString = dialec.getSequenceNextValString("SEQSIGNAT");
ResultSet rs = stmt.executeQuery(nextvalString);

while (rs.next()) {
  nextval = rs.getLong(1);
}


Questions:
1. How can I execute dialec.getSequenceNextValString("SEQSIGNAT") in hibernate without using JDBC? Is it possible?
2. How can I retrieve the dialect from object session without setting Property again( i have declared it in hibernate.properties and the session holds that information in object (session -> factory -> settings -> dialect=Oracle9Dialect) , but I don't know how to retrieve that information.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 02, 2005 7:53 pm 
Newbie

Joined: Fri Feb 04, 2005 9:45 am
Posts: 8
Location: Czech Republic
Guys
none of you know if it is possible?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 03, 2005 11:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The configuration object has the all the items including the dialect.
You use JDBC anyway (wrapped or unwrapped) there is no issue in geting the connection from the Hibernate Session and using straight JDBC. You do not need to create your own connection.


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