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.  [ 1 post ] 
Author Message
 Post subject: Help with year comparison
PostPosted: Fri Sep 01, 2006 9:16 pm 
Newbie

Joined: Fri Sep 01, 2006 8:47 pm
Posts: 1
Location: México
Hibernate version: 3.1.3

DBMS: Informix

I'm trying translate the next SQL query to HQL

Code:
select * from inventario_eqpo_nf
where id_inv_equipo = 1
and year(fecha_instalacion) = '2006'


This query works fine, but the HQL doesn't

This is the HQL I'm trying:
Code:
select ien from InventarioEqpoNf ien
where ien.idInvEquipo = 1
and year(ien.fechaInstalacion) = '2006'


The stackTrace:
    org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar [select inventario0_.id_inv_equipo as id1_23_, inventario0_.cve_comp as cve2_23_, inventario0_.id_grupo_eqpo as id3_23_, inventario0_.id_nodo as id4_23_, inventario0_.tipo_usuario as tipo5_23_, inventario0_.id_tipo_edificio as id6_23_, inventario0_.serial_nodo_eqpo as serial7_23_, inventario0_.fecha_instalacion as fecha8_23_, inventario0_.cantidad as cantidad23_, inventario0_.demanda_calc as demanda10_23_, inventario0_.demanda_real as demanda11_23_, inventario0_.fecha_lectura as fecha12_23_, inventario0_.ubicacion as ubicacion23_, inventario0_.sala as sala23_, inventario0_.cantidad_fallas as cantidad15_23_, inventario0_.fecha_ult_falla as fecha16_23_, inventario0_.historico_fallas as historico17_23_, inventario0_.cantidad_mtto_prev as cantidad18_23_, inventario0_.fecha_ult_prev as fecha19_23_, inventario0_.historico_prev as historico20_23_, inventario0_.estatus as estatus23_ from inventario_eqpo_nf inventario0_ where inventario0_.id_inv_equipo=1 and extract(year from inventario0_.fecha_instalacion)='2006']; nested exception is java.sql.SQLException: A syntax error has occurred.
    java.sql.SQLException: A syntax error has occurred.
    at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:373)
    at com.informix.jdbc.IfxSqli.a(IfxSqli.java:3208)
    at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3518)
    at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2353)
    at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2269)
    at com.informix.jdbc.IfxSqli.executePrepare(IfxSqli.java:1153)
    at com.informix.jdbc.IfxPreparedStatement.e(IfxPreparedStatement.java:318)
    at com.informix.jdbc.IfxPreparedStatement.a(IfxPreparedStatement.java:298)
    at com.informix.jdbc.IfxPreparedStatement.<init>(IfxPreparedStatement.java:168)
    at com.informix.jdbc.IfxSqliConnect.h(IfxSqliConnect.java:5918)
    at com.informix.jdbc.IfxSqliConnect.prepareStatement(IfxSqliConnect.java:1999)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:442)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:368)
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
    at org.hibernate.loader.Loader.doQuery(Loader.java:661)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    at org.hibernate.loader.Loader.doList(Loader.java:2145)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
    at org.hibernate.loader.Loader.list(Loader.java:2024)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    at org.springframework.orm.hibernate3.HibernateTemplate$31.doInHibernate(HibernateTemplate.java:853)
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
    at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:844)
    at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:836)
    at com.sigmatao.util.test.daoimpl.UtilConsultasParaTestDaoImpl.getEverything(UtilConsultasParaTestDaoImpl.java:40)
    at com.sigmatao.util.test.daoimpl.TestUtilConsultasParaTestDaoImpl.testgetEverything(TestUtilConsultasParaTestDaoImpl.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: java.sql.SQLException
    at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:373)
    at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3523)
    ... 47 more


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.