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.  [ 2 posts ] 
Author Message
 Post subject: Using Hibernate Criteria API for SQL OR
PostPosted: Mon Apr 02, 2007 3:59 pm 
Newbie

Joined: Wed Mar 07, 2007 5:37 pm
Posts: 2
I'm a newbie to Hibernate and I have been using HQL for the most part. I had a situation to where I need to build a very dynamic query and I thought the criteria api might the better choice.

However, I need to use SQL OR operations in my where clause.

So far, I have not found an example online or in Hibernate in Action that shows how to do this.

In addition, I'm looking to do this with the criteria api if possible:

HQL Sample:

Code:
Select entityResult
From Entity entityResult join EntityResult.customProperties resultProperty
Where (resultProperty.id = :id AND resultProperty.value=:value) OR
(repeat above statement)...


I thought I would just ask the forum since some google searching wasn't getting me anywhere!

Thanks,

Mike

P.S. I'm Using Hibernate 3.2.2

Code:


Top
 Profile  
 
 Post subject: try this
PostPosted: Tue Apr 03, 2007 12:04 am 
Beginner
Beginner

Joined: Thu Feb 01, 2007 3:08 am
Posts: 20
Use the below one



sess.createCriteria(Entity.class).createAlias("customProperties", "resultProperty")
.setProjection(Projections.property("entityResult"))
.add(Expression.or(Expression.and(Expression.eq("resultProperty.id",id),Expression.eq("resultProperty.value",value)),....)


PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.