-->
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: Error on using SQL Server CONVERT Function
PostPosted: Sat Jun 20, 2009 12:24 am 
Newbie

Joined: Fri Jun 19, 2009 1:20 pm
Posts: 4
Hi,

i'm new in Hibernate and currently i'm using Hibernate with SQL Server 2005. I have a query like this :

Code:
SELECT CONVERT(NVARCHAR(10), trDate, 111), product FROM detail GROUP BY CONVERT(NVARCHAR(10),trDate,111)


Once i call createSQLQuery of above query and i fetch a list, it always throw Exception. the exception is like this :

Code:
org.hibernate.exception.DataException: could not execute query
Caused by: java.sql.SQLException: The value supplied cannot be converted to DECIMAL.


and the log4j output :

Code:
Jun 19, 2009 1:35:55 PM org.hibernate.type.NullableType nullSafeGet
INFO: could not read column value from result set: ; The value supplied cannot be converted to DECIMAL.
Jun 19, 2009 1:35:55 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: 22000
Jun 19, 2009 1:35:55 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: The value supplied cannot be converted to DECIMAL.


Is there any problem with SQL Server 2005 integration? If i remove the CONVERT function, it works fine.. is there any clue? any help will be apreciated... thank you!


Top
 Profile  
 
 Post subject: Re: Error on using SQL Server CONVERT Function
PostPosted: Sun Jun 21, 2009 10:53 am 
Newbie

Joined: Fri Jun 19, 2009 1:20 pm
Posts: 4
please anyone? newbie here need help...


Top
 Profile  
 
 Post subject: Re: Error on using SQL Server CONVERT Function
PostPosted: Tue Jun 23, 2009 2:44 am 
Newbie

Joined: Fri Jun 19, 2009 1:20 pm
Posts: 4
SOLVED!

just simply adding addScalar to the query, and it's all done!

Code:
String query = "SELECT CONVERT(VARCHAR(10),dateTr,111) AS dat FROM table";

Query q = sf.createSQLQuery(query)
.addScalar("dat",Hibernate.STRING);


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.