-->
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.  [ 6 posts ] 
Author Message
 Post subject: boolean madness with hql
PostPosted: Thu Nov 30, 2006 1:12 pm 
Newbie

Joined: Thu Apr 13, 2006 7:53 pm
Posts: 4
Hibernate version: 3.1.2

Mapping documents:
<hibernate-mapping>
<class name="combase.korona.fach.datamodel.Organisationseinheit" table="ORG">
<!-- <cache usage="read-write" /> -->
<id name="id" type="long" unsaved-value="-1">
<column name="PK_ORG_ID" sql-type="long" not-null="true" />
<generator class="sequence">
<param name="sequence">GEN_KEYS</param>
</generator>
</id>
....
<property name="lager"/>
...


</class>

<query name="Organisationseinheit.findLager">
<![CDATA[
from Organisationseinheit org where lager is true
]]>
</query>


Full stack trace of any exception that occurs:

org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select organisati0_.PK_ORG_ID as PK1_20_, organisati0_.GEAENDERT as GEAENDERT20_, organisati0_.bezeichnung as bezeichn3_20_, organisati0_.FK_REPORTKONTO_ID as FK4_20_, organisati0_.FK_ORG_ID as FK5_20_, organisati0_.nummer as nummer20_, organisati0_.kurznummer as kurznummer20_, organisati0_.strasse as strasse20_, organisati0_.plz as plz20_, organisati0_.ort as ort20_, organisati0_.mail as mail20_, organisati0_.TEL as TEL20_, organisati0_.fax as fax20_, organisati0_.ansprechpartner as ansprec14_20_, organisati0_.mitarbeiter as mitarbe15_20_, organisati0_.fixkosten as fixkosten20_, organisati0_.handlungskosten as handlun17_20_, organisati0_.kontaktstrecke as kontakt18_20_, organisati0_.praesentationsflaeche as praesen19_20_, organisati0_.konzernzugehoerigkeit as konzern24_20_, organisati0_.GUELTIG_AB as GUELTIG20_20_, organisati0_.GUELTIG_BIS as GUELTIG21_20_, organisati0_.FK_ORGTYP_ID as FK23_20_, organisati0_.FK_SYSTEMGEBER_ID as FK25_20_, organisati0_.FK_MIETEINHEITSTYP_ID as FK26_20_, organisati0_.PACHTSATZ as PACHTSATZ20_, organisati0_.SYSTEMGEBUEHR as SYSTEMG28_20_, organisati0_.SERWAYBETRIEB as SERWAYB29_20_, organisati0_.lager as lager20_ from ORG organisati0_ where organisati0_.lager=1]; SQL state [HY000]; error code [335544334]; GDS Exception. 335544334. conversion error from string "Y"; nested exception is org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544334. conversion error from string "Y"
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544334. conversion error from string "Y"
at org.firebirdsql.jdbc.FBStatementFetcher.fetch(FBStatementFetcher.java:206)
at org.firebirdsql.jdbc.FBStatementFetcher.next(FBStatementFetcher.java:119)
at org.firebirdsql.jdbc.FBResultSet.next(FBResultSet.java:250)
at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.next(DelegatingResultSet.java:168)
at org.hibernate.loader.Loader.doQuery(Loader.java:685)
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:1129)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$34.doInHibernate(HibernateTemplate.java:920)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:911)
at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:903)
at combase.korona.storage.hibernate.current.HibernateBaseDAO.findByNamedQuery(HibernateBaseDAO.java:138)
at combase.korona.storage.hibernate.current.HibernateStoragemanager.findByNamedQuery(HibernateStoragemanager.java:100)
at combase.korona.fach.services.ApplicationService.findByNamedQuery(ApplicationService.java:849)
at combase.korona.webui.forms.ArtikelForm.putBestaende(ArtikelForm.java:1420)
at combase.korona.webui.forms.ArtikelForm.putDataObject(ArtikelForm.java:1285)
at combase.korona.tankrast.shared.webui.forms.ArtikelForm.putDataObject(ArtikelForm.java:146)
at combase.korona.webui.forms.ArtikelForm.putDataObject(ArtikelForm.java:1)
at combase.korona.webui.actions.ObjectAction.createView(ObjectAction.java:197)
at combase.korona.webui.actions.ObjectAction.executeEditAction(ObjectAction.java:289)
at combase.korona.webui.actions.ObjectAction.executeStxxAction(ObjectAction.java:104)
at combase.korona.webui.actions.StxxActionBase.executeKoronaAction(StxxActionBase.java:67)
at combase.korona.webui.shared.KoronaActionBase.executeUserAction(KoronaActionBase.java:39)
at combase.korona.webui.shared.UserAction.executeAction(UserAction.java:61)
at combase.korona.webui.shared.ActionBase.execute(ActionBase.java:45)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
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.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
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.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
at org.firebirdsql.gds.GDSException: conversion error from string "Y"
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2104)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.receiveResponse(AbstractJavaGDSImpl.java:2054)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscDsqlFetch(AbstractJavaGDSImpl.java:1322)
at org.firebirdsql.gds.impl.GDSHelper.fetch(GDSHelper.java:260)
at org.firebirdsql.jdbc.FBStatementFetcher.fetch(FBStatementFetcher.java:201)
at org.firebirdsql.jdbc.FBStatementFetcher.next(FBStatementFetcher.java:119)
at org.firebirdsql.jdbc.FBResultSet.next(FBResultSet.java:250)
at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.next(DelegatingResultSet.java:168)
at org.hibernate.loader.Loader.doQuery(Loader.java:685)
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:1129)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$34.doInHibernate(HibernateTemplate.java:920)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:911)
at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:903)
at combase.korona.storage.hibernate.current.HibernateBaseDAO.findByNamedQuery(HibernateBaseDAO.java:138)
at combase.korona.storage.hibernate.current.HibernateStoragemanager.findByNamedQuery(HibernateStoragemanager.java:100)
at combase.korona.fach.services.ApplicationService.findByNamedQuery(ApplicationService.java:849)
at combase.korona.webui.forms.ArtikelForm.putBestaende(ArtikelForm.java:1420)
at combase.korona.webui.forms.ArtikelForm.putDataObject(ArtikelForm.java:1285)
at combase.korona.tankrast.shared.webui.forms.ArtikelForm.putDataObject(ArtikelForm.java:146)
at combase.korona.webui.forms.ArtikelForm.putDataObject(ArtikelForm.java:1)
at combase.korona.webui.actions.ObjectAction.createView(ObjectAction.java:197)
at combase.korona.webui.actions.ObjectAction.executeEditAction(ObjectAction.java:289)
at combase.korona.webui.actions.ObjectAction.executeStxxAction(ObjectAction.java:104)
at combase.korona.webui.actions.StxxActionBase.executeKoronaAction(StxxActionBase.java:67)
at combase.korona.webui.shared.KoronaActionBase.executeUserAction(KoronaActionBase.java:39)
at combase.korona.webui.shared.UserAction.executeAction(UserAction.java:61)
at combase.korona.webui.shared.ActionBase.execute(ActionBase.java:45)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
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.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
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.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)

Name and version of the database you are using:

Firebird 1.5 / jaybird jdbc driver

The generated SQL (show_sql=true):
select ... from ORG organisati0_ where organisati0_.lager=1


So here is my problem:

Class Organisationseinheit has a property "lager" of type "Boolean". The corresponding table stores this in a field of type char(1). When storing and loading Organisationseinheit Objects, the JDBC Driver maps true to 'Y' and false to 'N'. This is all working well, hibernate just uses the jdbc driver for this. Now i introduced a query like this:
"from Organisationseinheit org where org.lager is true"
And suddenly, hibernate tries to get smart itself and produces this sql for the hql query:
select ... from ORG organisati0_ where organisati0_.lager=1
it uses an integer value (1 instead of '1') which is wrong and it uses the wrong semantics (1 instead of 'Y').
Now some RDBMs would balk at this because an integer is passed for a character field, and some (including firebird) try to compare the 'Y's and 'N's in the table to an integer and fail with an conversion error (see above). Changing the field type in the database is not an option, because i do not have control over this.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 2:02 pm 
Newbie

Joined: Mon Jan 05, 2004 11:04 am
Posts: 16
Hi,

try this

<property name="hibernate.query.substitutions">true 1, false 0</property>

or something like that.

_________________
_________________
Siegbert

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 7:49 pm 
Newbie

Joined: Thu Apr 13, 2006 7:53 pm
Posts: 4
yes, i could use this, but this is not jdbc-driver (and thus rdbms) independent. i connect to firebird or oracle or db2, and the oracle driver puts '0' and '1' in boolean, while firebirds jdbc driver uses 'Y' and 'N'.
maybe i could use a user type in hibernate to force a behaviour thats consistent across jdbc-drivers, and then apply your suggestion.
but really hibernate should do this for me. the framework could treat 'true' and 'false' as placeholders for bind parameters, and bind the appropriate value via jdbc-driver. if i define my query like this
'from Organisationseinheit org where lager=:isLager
and bind a boolean to 'isLager' parameter, all goes well.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 12:41 am 
Beginner
Beginner

Joined: Mon Jun 19, 2006 4:10 pm
Posts: 27
why store as a char? hsqldb has a boolean type....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 5:41 am 
Newbie

Joined: Thu Apr 13, 2006 7:53 pm
Posts: 4
as i said above. i have no influence on the database, as it is in production for quite a while. and i need an rdbms independent solution, otherwise siegberts advice would have been sufficient.
and hsqldb might be a pretty good database, but telling our clients to dump their db2s and oracles in favour of hsqldb, just because one of the apps connecting to the database uses a broken orm solution, is not an option.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 2:04 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
I do this all the time. Just make the type in the mapping file = "yes_no".
See the hibernate type in the java api called YesNoType or something like that.


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

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.