-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to use Criteria
PostPosted: Mon Sep 17, 2007 4:05 am 
Newbie

Joined: Mon Sep 17, 2007 3:58 am
Posts: 2
Hello,
i'm newbie at Hibernate. I'm using hibernate for building a desktop application with Oracle database.
I want to learn how use the criteria to do a query. I'm reading Hibernate reference.

Can you explain me (by example) where and how i can use criteria?

Thanks.
Regards.

_________________
Force and honor!!


Top
 Profile  
 
 Post subject: Criteria
PostPosted: Tue Sep 18, 2007 5:27 am 
Beginner
Beginner

Joined: Wed Jul 25, 2007 6:32 am
Posts: 22
You can use either Criteria or HQL (Named Queries)

HQL is powerfull with advanced features and usefull for more difficult problems.

Criteria allows you to built a query at runtime. But criteria are often less readable then HQL but are validated at compile time.

A Criteria is a tree of Criterion instances. (Restrictions return criterion instances).

For example:

Criteria criteria = session.createCriteria(User.class);
criteria.add(Restrictions.like("firstname", "Scott"); //add a criterion
List result = criteria.list();

firstname is the java property in the User Class and "Scott" is its value.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 5:53 am 
Newbie

Joined: Mon Sep 17, 2007 3:58 am
Posts: 2
Thanks....I've solved.

_________________
Force and honor!!


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