I have a set with the 'where' property as:
Code:
where="even_inicio >= DATE_SUB(NOW(), INTERVAL 30 DAY)"
But the generated SQL apparently interprets INTERVAL as a field in the table as seen in the generated SQL bellow.
Is this a bug? Is there a workaround it?
Thanks in advance
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelpHibernate version: 3.1
Mapping documents:Code:
<set name="ultimos"
inverse="false"
order-by="even_inicio"
table="oss_evento"
where="even_inicio >= DATE_SUB(NOW(), INTERVAL 30 DAY)">
<key column="even_nam_origem"/>
<one-to-many class="net.unicel.Bilhete"/>
</set>
Full stack trace of any exception that occurs:
17/08/2006 - 13:08:30 ERROR : (StandardWrapperValve.java:invoke:253) Servlet.service() for servlet action threw exception
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [net.unicel.Aparelho.ultimos#6]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1926)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1693)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
at org.hibernate.collection.PersistentSet.size(PersistentSet.java:114)
at net.unicel.actions.VerExtratoAction.execute(VerExtratoAction.java:50)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.hibernate.unicel.persistence.HibernateFilter.doFilter(HibernateFilter.java:40)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:831)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:639)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1203)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ultimos0_.INTERVAL 30 DAY) and ultimos0_.even_nam_origem=6 order by ultimos0_.' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2001)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1168)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1279)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2281)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1634)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
... 30 more
Name and version of the database you are using:
MySQL 5.0.19
The generated SQL (show_sql=true):
select
ultimos0_.even_nam_origem as even29_2_,
ultimos0_.even_id as even1_2_,
ultimos0_.even_segmento as even2_2_,
ultimos0_.even_id as even1_2_1_,
ultimos0_.even_segmento as even2_2_1_,
ultimos0_.even_id_coletor as even3_2_1_,
ultimos0_.even_address_coletor as even4_2_1_,
ultimos0_.even_mdn_origem as even5_2_1_,
ultimos0_.even_clie_id_destino as even6_2_1_,
ultimos0_.even_nam_destino as even7_2_1_,
ultimos0_.even_mdn_destino as even8_2_1_,
ultimos0_.even_clie_id_pagador as even9_2_1_,
ultimos0_.even_nam_id_pagador as even10_2_1_,
ultimos0_.even_localidade as even11_2_1_,
ultimos0_.even_inicio as even12_2_1_,
ultimos0_.even_fim as even13_2_1_,
ultimos0_.even_duracao as even14_2_1_,
ultimos0_.even_custo_atual as even15_2_1_,
ultimos0_.even_id_custo_atual as even16_2_1_,
ultimos0_.even_tipo_evento as even17_2_1_,
ultimos0_.even_tipo_iniciacao as even18_2_1_,
ultimos0_.even_motivo_principal as even19_2_1_,
ultimos0_.even_motivo_secundario as even20_2_1_,
ultimos0_.even_evento_completado as even21_2_1_,
ultimos0_.even_infoextras0 as even22_2_1_,
ultimos0_.even_infoextras1 as even23_2_1_,
ultimos0_.even_infoextras2 as even24_2_1_,
ultimos0_.even_infoextras3 as even25_2_1_,
ultimos0_.even_infoextras4 as even26_2_1_,
ultimos0_.even_infoextras5 as even27_2_1_,
ultimos0_.even_desviado as even28_2_1_,
ultimos0_.even_nam_origem as even29_2_1_,
ultimos0_.even_clie_id_origem as even30_2_1_,
localidade1_.loca_codigo_cnl as loca1_6_0_,
localidade1_.loca_sigla_cnl as loca2_6_0_,
localidade1_.loca_uf as loca3_6_0_,
localidade1_.loca_area_tarifacao as loca4_6_0_,
localidade1_.loca_localidade as loca5_6_0_,
localidade1_.loca_municipio as loca6_6_0_
from
oss_evento ultimos0_
left outer join
oss_localidade localidade1_
on ultimos0_.even_infoextras1=localidade1_.loca_codigo_cnl
where
ultimos0_.even_inicio >= DATE_SUB(NOW(), ultimos0_.INTERVAL 30 DAY)
and ultimos0_.even_nam_origem=?
order by
ultimos0_.even_inicio