• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add two criteria with Disjunction in hibernate.

 
Roopesh Rana
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roopesh Rana
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.............



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic