Friday 30 January 2015

HIbernate : How to get more details on "Errors in Named Queries"


ERROR Seen when there is a problem in the named query 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Dao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DaoImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/sessionfactory-cfg.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Errors in named queries: select_records_with_auth


Just gives you a high level error.

To get more details change the loglevel. (Below example is of log4j)

<logger name='org.hibernate' level='DEBUG' additivity="false">
        <appender-ref ref='DebugLogFile'/>
</logger>

you will get indepth details as shown below

2015-01-30 14:46:29.864 UTC,ERROR,***-web,,org.hibernate.hql.PARSER,null,RMI TCP Connection(3)-127.0.0.1,line 2:10: expecting IDENT, found '*'
2015-01-30 14:46:29.874 UTC,DEBUG,index-web,,org.hibernate.hql.ast.ErrorCounter,null,RMI TCP Connection(3)-127.0.0.1,line 2:10: expecting IDENT, found '*'
antlr.MismatchedTokenException: expecting IDENT, found '*'
        at antlr.Parser.match(Parser.java:211) ~[antlr.jar:na]
        at org.hibernate.hql.antlr.HqlBaseParser.identifier(HqlBaseParser.java:1612) [hibernate-core.jar:3.6.10.Final]
        at org.hibernate.hql.antlr.HqlBaseParser.atom(HqlBaseParser.java:3691) [hibernate-core.jar:3.6.10.Final]


2 comments: