permaculture playing cards*
The moose likes Object Relational Mapping and the fly likes How to add two criteria with Disjunction in hibernate. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to add two criteria with Disjunction in hibernate." Watch "How to add two criteria with Disjunction in hibernate." New topic
Author

How to add two criteria with Disjunction in hibernate.

Roopesh Rana
Greenhorn

Joined: Sep 03, 2012
Posts: 15
Hi All

Please help me

Both tables are joined with left_join

I have two criterion, first one having records where
Criterion nonCyc = Restrictions.isNull(propertyName);
Criterion cyc = restrictions.isNotNull(propertyName);

(propertyName are same in both criterion.)

Criteria crit = session.createCriteria(User.class);
crit.add(Restrictions.or(nonCyc, cyc));


This is working.

But question is --> I have four String parameters also which are will be apply on 2nd Criterion (Criterion cyc = restrictions.isNotNull(propertyName))

So please help me how to apply String parameters on Criterion query

Thanks
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Please UseCodeTags . I am having a hard time understanding what you are asking. It is often useful with questions like this to post

1. The entire criteria you have right now. Also include the SQL it generates or the stack trace of the exception you are getting.
2. The SQL you are expecting the criteria query to produce.
3, Include enough information about the entities and relationships that we can make sense of the problem

Are you using the Restrictions class in org.hibernate.criterion.Restrictions? If so have a look at the conjuction and disjunction methods.


[How To Ask Questions][Read before you PM me]
Roopesh Rana
Greenhorn

Joined: Sep 03, 2012
Posts: 15
Bill Gorder wrote:Please UseCodeTags . I am having a hard time understanding what you are asking. It is often useful with questions like this to post

1. The entire criteria you have right now. Also include the SQL it generates or the stack trace of the exception you are getting.
2. The SQL you are expecting the criteria query to produce.
3, Include enough information about the entities and relationships that we can make sense of the problem

Are you using the Restrictions class in org.hibernate.criterion.Restrictions? If so have a look at the conjuction and disjunction methods.


Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Why are you using transient fields in your query and why are the types not String like your getters and setters?

Also you still have not posted any exception you are getting nor have you posted the SQL you are expecting the JPQL to generate for you.
Roopesh Rana
Greenhorn

Joined: Sep 03, 2012
Posts: 15
Bill Gorder wrote:Why are you using transient fields in your query and why are the types not String like your getters and setters?

Also you still have not posted any exception you are getting nor have you posted the SQL you are expecting the JPQL to generate for you.




Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

When I say SQL I mean the straight SQL that you are expecting hibernate to generate without JPA or hibernate markup

for example.



Anyway that is a weird exception I have never seen it before. Upon googling there was a JIRA for a similar exception back some time ago, but it was fixed. What version of hibernate are you using?

Also you never answered my question as to why you are using transient fields in your query. I would remove those.

Roopesh Rana
Greenhorn

Joined: Sep 03, 2012
Posts: 15
Bill Gorder wrote:When I say SQL I mean the straight SQL that you are expecting hibernate to generate without JPA or hibernate markup

for example.



Anyway that is a weird exception I have never seen it before. Upon googling there was a JIRA for a similar exception back some time ago, but it was fixed. What version of hibernate are you using?

Also you never answered my question as to why you are using transient fields in your query. I would remove those.



Roopesh Rana wrote: Hibernate version is 3.3
yes, we can remove transient keyword as well as Variable also, we can use String type of variables





Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Yes I would remove the transients. I would also upgrade your hibernate to at least the latest 3.x version. That is just a weird exception to be getting and since there was a JIRA for it, it might be addressed in a later version. I will take a look at your query again later when I get a chance.
Roopesh Rana
Greenhorn

Joined: Sep 03, 2012
Posts: 15
Bill Gorder wrote:Yes I would remove the transients. I would also upgrade your hibernate to at least the latest 3.x version. That is just a weird exception to be getting and since there was a JIRA for it, it might be addressed in a later version. I will take a look at your query again later when I get a chance.


Roopesh Rana wrote: Thanks every body, I found solution of this problem

There are two entity classes 1st one is Library and 2nd one is Book.
In Library entity we have one property LNGBOOKID. LNGBOOKID property have some null as well as not null values.
Then we joined both tables.............



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add two criteria with Disjunction in hibernate.
 
Similar Threads
feedback on this proposed design
HQL -> Criteria....
isNotNull & isNotEmpty Hibernate
fetching records by using hql and criteria is taking more time
Need Hibernate Criteria help.