`

org.hibernate.QueryException: query must begin with SELECT or FROM解决方案

 
阅读更多

 

hibernate自带HQL一般只用于查询语句,而增删改需要在query执行之后再调用query.executeUpdate();

但是经测试后一直报异常如下:
org.hibernate.QueryException: query must begin with SELECT or FROM:
 
原因:
hibernate 配置文件hibernate.cfg.xml里 解析hibernate 查询语言为2.X版本。

 解决办法:
<property name="hibernate.query.factory_class">
        org.hibernate.hql.classic.ClassicQueryTranslatorFactory </property>

将其改为3.X
<property name="hibernate.query.factory_class">
       org.hibernate.hql.ast.ASTQueryTranslatorFactory
</property> 
 
或者
 

2.x :hibernate.query.factory_class=org.hibernate.hql.classic.ClassicQueryTranslatorFactory   

3.x:hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory 

 

原帖地址:http://k0441258778983.iteye.com/blog/1042580

参考地址:http://kangzye.blog.163.com/blog/static/3681922320098311461766/

 

添加后可能出现如下异常:

java.lang.NoClassDefFoundError: antlr/ANTLRException


增加antlr-2.7.6.jar这个包就OK了!

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics