-->
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: HQL "OR" Problem
PostPosted: Thu Oct 09, 2008 6:08 am 
Newbie

Joined: Thu Oct 09, 2008 5:22 am
Posts: 1
Hi

I am using Hibernate3 with mysql 5.0.51 and I've noticed HQL is evaluating some
expressions NOT as I expected.

My first query is as follows:

query = "select A from ImportAntrag as A
where A.originalId='0'
and A.antrag_id >= 1346 and A.antrag_id <= 1346
and A.originalImpBokId='0'
and A.dienststelle.bundesland=?";
params.add(inspektor.getDienststelle().getBundesland());

Session session = getHibernateTemplate().getSessionFactory().openSession();

session.beginTransaction();

Query hql = session.createQuery(query);
for (int i = 0; i < params.size(); i++) {
hql.setParameter(i, params.get(i));
}
List<ImportAntrag> ret = (List<ImportAntrag>) hql.list();
System.out.println("cuantos: " + ret.size());

which return 1 record which is correct.

but if I add a constraint more

query = "select A from ImportAntrag as A
where A.originalId='0'
and A.antrag_id >= 1346 and A.antrag_id <= 1346
and A.originalImpBokId='0'
and (A.dienststelle.bundesland=? OR
A.dienststelleBOK.bundesland=?)";

params.add(inspektor.getDienststelle().getBundesland());
params.add(inspektor.getDienststelle().getBundesland());

The resulting set is EMPTY.

What I can say is that the exspression

dienststelleBOK.bundesland

might be null (in fact it is null for this case).

How should I specify the query in order to get the correct
result set. Or in other words, What am I doing wrong?

Thanks in advance

Luis


BTW, the generated code is as follows

Hibernate:
select
importantr0_.ANTRAG_ID as id37_,
importantr0_1_.absender as absender37_,
importantr0_1_.ansprechpartner as ansprech2_37_,
importantr0_1_.antragfuer as antragfuer37_,
importantr0_1_.antragsteller as antrags50_37_,
importantr0_1_.barzahlung as barzahlung37_,
importantr0_1_.bearbeitungstatus as bearbei51_37_,
importantr0_1_.bemerkungAS as bemerkun4_37_,
importantr0_1_.bemerkungGebuehren as bemerkun5_37_,
importantr0_1_.bemerkungInsp as bemerkun6_37_,
importantr0_1_.besichtigungsDatum as besichti7_37_,
importantr0_1_.besichtigungsort as besichti8_37_,
importantr0_1_.dienststelle as diensts52_37_,
importantr0_1_.empfaenger as empfaenger37_,
importantr0_1_.ersatzAntragId as ersatzAn9_37_,
importantr0_1_.erstellDatum as erstell10_37_,
importantr0_1_.erstellerFirma_id as erstell54_37_,
importantr0_1_.gebuehrManuellExportiert as gebuehr11_37_,
importantr0_1_.gebuehrenstatus as gebuehr55_37_,
importantr0_1_.gebuehrenTransNr as gebuehr12_37_,
importantr0_1_.gebuhrenBOKInitAutoDone as gebuhre13_37_,
importantr0_1_.gebuhrenInitAutoDone as gebuhre14_37_,
importantr0_1_.hauptWarenGruppeCode as hauptWa15_37_,
importantr0_1_.inspektor as inspektor37_,
importantr0_1_.kennzeichenDerSendung as kennzei16_37_,
importantr0_1_.lastModified as lastMod17_37_,
importantr0_1_.lockId as lockId37_,
importantr0_1_.ohneGebuehr as ohneGeb19_37_,
importantr0_1_.originalId as originalId37_,
importantr0_1_.rechnungsempfaenger as rechnun57_37_,
importantr0_1_.referenznrRechnungsempfaenger as referen21_37_,
importantr0_1_.sortAbfertigungsDatum as sortAbf22_37_,
importantr0_1_.sortAbsender as sortAbs23_37_,
importantr0_1_.sortAbsenderland as sortAbs24_37_,
importantr0_1_.sortAntragsteller as sortAnt25_37_,
importantr0_1_.sortArt as sortArt37_,
importantr0_1_.sortAusstellungsdatum as sortAus27_37_,
importantr0_1_.sortBearbeitungsStatus as sortBea28_37_,
importantr0_1_.sortBesichtigungDatum as sortBes29_37_,
importantr0_1_.sortDienststelle as sortDie30_37_,
importantr0_1_.sortDienststelleBO as sortDie31_37_,
importantr0_1_.sortDienststelleEO as sortDie32_37_,
importantr0_1_.sortEmpfaenger as sortEmp33_37_,
importantr0_1_.sortEmpfaengerland as sortEmp34_37_,
importantr0_1_.sortErstellDatum as sortErs35_37_,
importantr0_1_.sortGeb2Status as sortGeb36_37_,
importantr0_1_.sortGebStatus as sortGeb37_37_,
importantr0_1_.sortInsp as sortInsp37_,
importantr0_1_.sortInspBO as sortInspBO37_,
importantr0_1_.sortInspEO as sortInspEO37_,
importantr0_1_.sortPgzNr as sortPgzNr37_,
importantr0_1_.sortPrePrintedNr as sortPre42_37_,
importantr0_1_.sortWarengruppe as sortWar43_37_,
importantr0_1_.statistikTransDatum as statist44_37_,
importantr0_1_.statistikTransNr as statist45_37_,
importantr0_1_.transport as transport37_,
importantr0_1_.transportmittel as transpo46_37_,
importantr0_1_.verworfenerAntragId as verworf47_37_,
importantr0_1_.weiterleitung as weiterl59_37_,
importantr0_.agoz as agoz43_,
importantr0_.ankunftstDatum as ankunfts2_43_,
importantr0_.barzahlung2 as barzahlung3_43_,
importantr0_.behandlung as behandlung43_,
importantr0_.behandlungHolzUrsprung as behandlu4_43_,
importantr0_.bemerkungGebuehren2 as bemerkun5_43_,
importantr0_.bemerkungWL as bemerkun6_43_,
importantr0_.bestimOrtKont as bestimOr7_43_,
importantr0_.containerNr as containe8_43_,
importantr0_.dienststelleBOK as diensts32_43_,
importantr0_.eingangsort as eingang33_43_,
importantr0_.eingangsortText as eingangs9_43_,
importantr0_.frachtpapiereNr as frachtp10_43_,
importantr0_.gebuehrManuellExportiert2 as gebuehr11_43_,
importantr0_.gebuehrenTransNr2 as gebuehr12_43_,
importantr0_.genehKontOrtA as genehKo13_43_,
importantr0_.genehKontOrtB as genehKo14_43_,
importantr0_.gesamtePreis as gesamte15_43_,
importantr0_.gesamtePreisBOK as gesamte16_43_,
importantr0_.herkunftsland as herkunf34_43_,
importantr0_.inspBestimmungsort as inspBes35_43_,
importantr0_.ippc as ippc43_,
importantr0_.kontroll as kontroll43_,
importantr0_.ohneGebuehr2 as ohneGeb18_43_,
importantr0_.originalImpBokId as origina19_43_,
importantr0_.pflanzenPass as pflanze20_43_,
importantr0_.pgzOrigDatum as pgzOrig21_43_,
importantr0_.pgzOrigNummer as pgzOrig22_43_,
importantr0_.rechnungsempfaenger2 as rechnun37_43_,
importantr0_.referenznrRechnungsempfaenger2 as referen23_43_,
importantr0_.regNumEinfuehrer as regNumE24_43_,
importantr0_.taricCode as taricCode43_,
importantr0_.transportMittelKennz as transpo26_43_,
importantr0_.verpackHolz as verpack27_43_,
importantr0_.weiterTransport as weiterT28_43_,
importantr0_.zollpapiereNr as zollpap29_43_,
importantr0_.gebuehrenstatus as gebuehr38_43_
from
importantrag importantr0_
inner join
antrag importantr0_1_
on importantr0_.ANTRAG_ID=importantr0_1_.id,
dienststelle dienststel1_,
dienststelle dienststel2_
where
importantr0_.dienststelleBOK=dienststel1_.dienststelleKuerzel
and importantr0_1_.dienststelle=dienststel2_.dienststelleKuerzel
and importantr0_1_.originalId='0'
and importantr0_.ANTRAG_ID>=1346
and importantr0_.ANTRAG_ID<=1346
and importantr0_.originalImpBokId='0'
and (
dienststel1_.bundesland=?
or dienststel2_.bundesland=?
)


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.