I think the proper syntax would be to "add" the left hand operator and then or the conditional with this. Rather than 2 ors which are right hand conditionals. E.g., the proper syntax would be:
Criteria criteria = new Criteria(); criteria.add("user.first_name", "John"); criteria.or("user.last_name", "Doe"); UserPeer.doSelect(criteria); The syntax using two the .or methods is like trying to write an SQL statement like: Select * from user where or user.first='John' or user.last='Doe'; The SQL parser would choke on this. I suspect the code is assuming that since there is no right hand conditional the or should be treated as an and statement. E.g. "Null or X" is translated to just X. It probably should throw an invalid syntax error here. FWIW, using Criterion is really only "required" if you are using the same column or need parenthetical nesting. > -----Original Message----- > From: Ivano Luberti [mailto:lube...@archicoop.it] > Sent: Friday, February 05, 2010 9:08 AM > To: Apache Torque Users List > Subject: Re: Criteria.or not working? > > Sorry never tried that, I only now that is not the way the Criteria > class is meant to be used. > So I let developers talk about that. > Alternatively you can dig into the peer classes source code: I have done > a few times to understand Torque behaviour and is quite well written and > readable > > Ludwig Magnusson ha scritto: > > Yes that works, but that was not what I asked. > > My question was, how can the methods and(), add() and or() all generate > the > > same result? > > > > -----Original Message----- > > From: Ivano Luberti [mailto:lube...@archicoop.it] > > Sent: den 5 februari 2010 14:10 > > To: Apache Torque Users List > > Subject: Re: Criteria.or not working? > > > > If you want to combine clauses mixinn and and or operators you should > > use Criterion. > > > > Look here for an introduction to how build queries using Criteria and > > Criterion > > > > http://db.apache.org/torque/releases/torque-3.3/runtime/reference/read- > from- > > db.html > > > > Ludwig Magnusson ha scritto: > > > >> Hi! > >> > >> I have done some testing during development of a project here and it > seems > >> that criteria.and([parameters]), criteria.add([parameters]) and > >> criteria.or([parameters]) all generate the same query to the database. > >> > >> > >> > >> E.g these three code snippets: > >> > >> Criteria criteria = new Criteria(); > >> > >> criteria.and("user.first_name", "John"); > >> > >> criteria.and("user.last_name", "Doe"); > >> > >> UserPeer.doSelect(criteria); > >> > >> > >> > >> Criteria criteria = new Criteria(); > >> > >> criteria.add("user.first_name", "John"); > >> > >> criteria.add("user.last_name", "Doe"); > >> > >> UserPeer.doSelect(criteria); > >> > >> > >> > >> Criteria criteria = new Criteria(); > >> > >> criteria.or("user.first_name", "John"); > >> > >> criteria.or("user.last_name", "Doe"); > >> > >> UserPeer.doSelect(criteria); > >> > >> > >> > >> . would all generate the Sql query > >> > >> SELECT * FROM USER WHERE first_name = "John" AND last_name = "Doe"; > >> > >> > >> > >> How can this be? > >> > >> /Ludwig > >> > >> > >> > >> > > > > > > -- > ================================================== > dott. Ivano Mario Luberti > Archimede Informatica societa' cooperativa a r. l. > Sede Operativa > Via Gereschi 36 - 56126- Pisa > tel.: +39-050- 580959 > tel/fax: +39-050-9711344 > web: www.archicoop.it > ================================================== > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: torque-user-unsubscr...@db.apache.org > For additional commands, e-mail: torque-user-h...@db.apache.org DukeCE Privacy Statement: Please be advised that this e-mail and any files transmitted with it are confidential communication or may otherwise be privileged or confidential and are intended solely for the individual or entity to whom they are addressed. If you are not the intended recipient you may not rely on the contents of this email or any attachments, and we ask that you please not read, copy or retransmit this communication, but reply to the sender and destroy the email, its contents, and all copies thereof immediately. Any unauthorized dissemination, distribution or copying of this communication is strictly prohibited. --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscr...@db.apache.org For additional commands, e-mail: torque-user-h...@db.apache.org