-->
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.  [ 1 post ] 
Author Message
 Post subject: Native SQL using hibernate
PostPosted: Thu Sep 16, 2004 6:55 pm 
Newbie

Joined: Thu Sep 16, 2004 6:37 pm
Posts: 1
[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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.