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.