[b]Hibernate version:2.1.6
Hi,
I am new to hibernate, I would like to try out whether hibernate allow to use native SQL in query?
I found this topic in <Hibernate in Action>, which mention hibernate allow to get the jdbc connection from the session object. However this way is not encourage. May I know what is the place that I have to pay attention if I really need to use native SQL with hibernate?
Below is my test code by using the native SQL in hibernate:
Session session = _sessions.openSession();
Transaction tx = null;
try
{
Connection con = session.connection();
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery("select blog.BLOG_ID,
blog.name, count(blog.BLOG_ID) from BLOGS as
blog left join BLOG_ITEMS as blogItems On
blog.BLOG_ID=blogItems.BLOG_ID group by
blog.BLOG_ID, blog.name order by
max(blogItems.date_time)");
while(uprs.next())
{
String id = result.getString("BLOG_ID");
String name = result.getString("name");
String count = result.getString(3);
System.out.println("Using native SQL Blog Name "+ name+
" BlodItemCount " +count);
}
stmt.close();
uprs.close();
}
catch (SQLException he)
{
}
The above code run well and able to retrieve the value from the datbase, however some SQL Warning was thrown:
(util.JDBCExceptionReporter 20 ) SQL Warning: 0, SQLState:
(util.JDBCExceptionReporter 28 ) [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to test
(util.JDBCExceptionReporter 20 ) SQL Warning: 0, SQLState:
(util.JDBCExceptionReporter 28 ) [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed database context to 'test'.
(util.JDBCExceptionReporter 20 ) SQL Warning: 0, SQLState:
(util.JDBCExceptionReporter 28 ) [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to us_english
(util.JDBCExceptionReporter 20 ) SQL Warning: 0, SQLState:
(util.JDBCExceptionReporter 28 ) [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed language setting to us_english.
Am I doing the correct thing? Or do I miss out something on my code? How can I get those warning out?
Thanks a lot for the help.
p/s:The same HSQL query doesnt give me those warning.
|