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语句

你可能感兴趣的:(Hibernate,OpenSource)