-->
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.  [ 2 posts ] 
Author Message
 Post subject: need help about native sql query
PostPosted: Tue Mar 20, 2007 2:02 am 
Newbie

Joined: Tue Mar 20, 2007 1:45 am
Posts: 2
Hi, i am new to hibernate so i am not sure the way i trying to do is correct or not, but i had create a function to handle all native select ...

public List getBySQLQuery(String query){
return getSession().createSQLQuery(query).list();
}

here my probelm is...when i try to create the sql and pass it to the function, it will sometimes throws me with exception : INFO [Thread-44] BigIntegerType.nullSafeGet(132) | could not read column value from result set: ; Column '' not found.
WARN [Thread-44] JDBCExceptionReporter.logExceptions(71) | SQL Error: 0, SQLState: S0022
ERROR [Thread-44] JDBCExceptionReporter.logExceptions(72) | Column '' not found.

but i copy the sql that used by hibernate and run it in sql client, it's works and the result set return.


This is a successful query :
select history.create_date as create_date, component.component_name as component_name, user.name as name, count(*) as hours from task_history as history left join user as user on history.user_id = user.user_id left join component as component on history.component_id = component.component_id left join country as country on history.country_id = country.country_id where 1 and history.country_id = 3 and history.shortcode is null and history.component_id = 10 and history.create_date between 20070303 and 20070320 group by history.user_id, history.create_date, history.component_id

and this is a fail one :
select history.create_date as create_date, component.component_name as component_name, user.name as name, count(*) as hours from task_history as history left join user as user on history.user_id = user.user_id left join component as component on history.component_id = component.component_id left join country as country on history.country_id = country.country_id where 1 and history.country_id = 3 and history.shortcode is null and history.component_id = 10 and history.user_id = 27 and history.create_date between 20070303 and 20070320 group by history.user_id, history.create_date, history.component_id

the difficult between this 2 pair is that there is history.user_id in the where clause...

another success one:
Hibernate: select history.create_date as create_date, component.component_name as component_name, user.name as name, count(*) as hours from task_history as history left join user as user on history.user_id = user.user_id left join component as component on history.component_id = component.component_id left join country as country on history.country_id = country.country_id where 1 and history.country_id = 3 and history.shortcode is null and history.component_id = 10 and history.user_id = 27 and history.create_date between 20070301 and 20070320 group by history.user_id, history.create_date, history.component_id

for this success one, if you compare with the fail one, you will find just the start date of create_date is changed...I really got no idea on why will have such problem....maybe the way i try to use the native query is wrong...

here is the exception found on fail one:
INFO [Thread-44] BigIntegerType.nullSafeGet(132) | could not read column value from result set: ; Column '' not found.
WARN [Thread-44] JDBCExceptionReporter.logExceptions(71) | SQL Error: 0, SQLState: S0022
ERROR [Thread-44] JDBCExceptionReporter.logExceptions(72) | Column '' not found.
Mar 20, 2007 1:55:30 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:616
SEVERE: >>org.hibernate.exception.SQLGrammarException: could not execute query
[SQL: 0, S0022]
>>java.sql.SQLException: Column '' not found.
>> at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
>> at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:955)
>> at com.mysql.jdbc.ResultSet.getBigDecimal(ResultSet.java:1226)
>> at org.apache.commons.dbcp.DelegatingResultSet.getBigDecimal(DelegatingResultSet.java:304)
>> at org.apache.commons.dbcp.DelegatingResultSet.getBigDecimal(DelegatingResultSet.java:304)
>> at org.hibernate.type.BigIntegerType.get(BigIntegerType.java:34)
>> at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
>> at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:139)

i really got no idea on why such thing would happen, maybe the way i try is wrong...but i got no idea on why sometimes it works but sometimes not....

I would be appreciate if any one can help me...Many thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 2:08 am 
Newbie

Joined: Tue Mar 20, 2007 1:45 am
Posts: 2
Hibernate version i am using : Hibernate 3.2 cr2


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