Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Hibernate Hibernate Criteria Expression Or

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

6 comments so far (post your own) View All Comments Latest 10 Comments:

session.createCriteria(Obj.class)
.add(Restrictions.disjunction()
.add(Restrictions.eq("firstname", iAmLookingFor))
.add(Restrictions.eq("secondname", iAmLookingFor))
.add(Restrictions.eq("thirdname", iAmLookingFor))
.add(Restrictions.eq("description ", iAmLookingFor))
);

Posted by Hibernate on Wednesday, 12.16.09 @ 19:56pm | #93419

What i should do in case when it's need to use more then two OR ?
like:
WHERE
firstname LIKE ".." OR
secondname LIKE ".." OR
thirdname LIKE ".." OR
description LIKE ".."


reply:

you can do somthing like this:

search = "%"+search+"%";
Criteria criteria = session.createCriteria(your.class);
criteria.add(
Expression.or(
Expression.or(
Expression.ilike("colum", search),
Expression.ilike("columx", search)
),
Expression.or(
Expression.or(
Expression.ilike("columx+1", search),
Expression.ilike("columx+2", search)
),
Expression.or(
Expression.ilike("columx+3", search),
Expression.ilike("columx+4", search)
)
)
)
);

this is not a realy good way of doing it but it works.

Posted by sdf on Saturday, 11.15.08 @ 00:09am | #81685

@iBog you can use the following template to make several OR,since methods are recursive:
criteria.add(Expression.or(
Expression.or(
Expression.eq(A1, A2),
Expression.eq(A3, A4)),
Expression.or(
Expression.eq(A5, A6),
Expression.or(
Expression.eq(A7, A8),
Expression.eq(A9, A10))
)
)
);

Posted by aymen on Monday, 10.20.08 @ 19:15pm | #81203

What i should do in case when it's need to use more then two OR ?
like:
WHERE
firstname LIKE ".." OR
secondname LIKE ".." OR
thirdname LIKE ".." OR
description LIKE ".."

Posted by iBog on Friday, 09.12.08 @ 15:18pm | #78875

I've searched on internet and these statements satisfy my condition:
Criteria crit = sess.
createCriteria(Insurance.class);
crit.add(Expression.or
(Expression.eq("lngInsuranceId",new Long(3)),
Expression.eq("lngInsuranceId",new Long(6))));

Thank you very much!

Posted by Thunn on Wednesday, 04.9.08 @ 12:31pm | #55723

Hi,
I have a problem in writing a criteria expression for nested properties.
Say your "insurance" table has a column "brokerid" and it's the primary key in table "insurance_broker". That table has fields for name, address, etc.
And assume those tables are properly mapped in mapping files.

I want to write something like

Expression.or
(Expression.eq("insurance_name",new Long(3)),
Expression.eq("insurance_broker.name","Test Broker")));

Thanks in advance

Posted by Chamara Ranasinghe on Friday, 01.11.08 @ 13:12pm | #44968

Ask programming questions?

 

 

Back to Tutorial

 

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.