-->
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.  [ 4 posts ] 
Author Message
 Post subject: something about the Criteria
PostPosted: Fri Jun 02, 2006 3:40 am 
Newbie

Joined: Fri Jun 02, 2006 3:25 am
Posts: 2
Hi
I met a problem when I use the class org.hibernate .Criteria

my code were as follow:
//
User user=new User("good");
Example example=Example.create(user)
.excludeZeroes()
.excludeProperty("password") .ignoreCase() .enableLike();
List result=session.createCriteria(User.class)
.add(example).list();
//

the problem is when i use the primary key as a filter ,it will get all the rows in the database out,if I use other column else,it will work all right.
my question is can't we use primary key?

when i use primary key ,the sql Hibernate created is as follow:

select this_.username as username0_, this_.password as password1_0_, this_.email as email1_0_, this_.ranking as ranking1_0_, this_.created as created1_0_, this_.street as street1_0_, this_.zipcode as zipcode1_0_, this_.city as city1_0_, this_.firstname as firstname1_0_, this_.lastname as lastname1_0_ from user this_ where (1=1)
why the where condition is always true?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 5:37 am 
Newbie

Joined: Fri Jun 02, 2006 3:25 am
Posts: 2
can anyone help me?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 5:49 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Referring to Hibernate reference document 15.6 Example queries, it says

"The class org.hibernate.criterion.Example allows you to construct a query criterion from a given instance. Version properties, identifiers and associations are ignored."


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 1:29 pm 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

Answer to your Question.

Criteria creates query in the runtime based on the values which you pass in. So ideally you will use to search a DB Table with 2 to n condition.

If you know that it is a PK then u can use the session.get(Object Instance, pk)

Bottom Line: Criteria API is not meant to search DB table based on PK.

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.