Hibernate查詢BUG

String hql="from Calls where idClient = ? and callStart > '"+startdt+"' and callStart < '"+enddt+"' ";	
Session session = null;
try {
session = HibernateDaoUtil.getSession();
Query query = session.createQuery(hql);

query.setParameter(0, idJiveuser);


org.hibernate.HibernateException: ordinal parameter mismatch

官方告示
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1423

在org.hibernate.engine.query.ParameterParser源碼類中有下列一段代碼
public static void parse(String sqlString, Recognizer recognizer) throws QueryException{
boolean hasMainOutputParameter = sqlString.indexOf( "call" ) > 0 &&
sqlString.indexOf( "?" ) < sqlString.indexOf( "call" ) &&
sqlString.indexOf( "=" ) < sqlString.indexOf( "call" );
......
}
我們都知道hibernate3可以調用存儲過程或函數,但是有一定的限制(具體可以查看hibernate官方手冊)。
據我分析這段代碼應該是用來分析字符串是否是調用存儲過程或函數的語句。
解決方法:
1.不要在表或列中,出現"call"字樣
2.用Criteria來代替hql語句
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章