-->
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: Need Help - Convertion Query to Criteria...
PostPosted: Tue Jun 24, 2008 12:02 pm 
Newbie

Joined: Wed Jun 18, 2008 12:21 pm
Posts: 2
Hi All,

Please help me following Oracle query how to convert into Criteria...?

select
(field1 - field2) as holdings
from
table_name
order by
holdings
desc


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 24, 2008 12:29 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, a good place to start would be gathering a solid understanding of how the Criteria API works. Here's a very simple tutorial on how to get started with the Hibernate3 Criteria API:

http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=09howtousethecriteriaapi

With the Criteria API, you need objects, not tables. So the table names you provide aren't really relevant - what is relevant is the object, or objects, that have the required mappings. That's what the criteria API is all about - thinking about your data in the form of object, rather than tables and columns. It's a subtle difference, but it's an important difference.

I think you'll likely find an Example object is appropriate for this type of scenario. Here's a simple use of the Criteria APIs Example class:

Code:
package com.examscam.criteria;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Example;
import com.examscam.HibernateUtil;
import com.examscam.model.User;

public class FindVerifiedUsers {
  public static void main(String[] args) {
    User user = new User();
    user.setVerified(false);
    Example example = Example.create(user);
    Session session = HibernateUtil.beginTransaction();
    Criteria criteria = session.createCriteria(User.class);
    criteria.add(example);
    List results = criteria.list();
    HibernateUtil.commitTransaction();
    for (int i = 0; i<results.size(); i++) {
      System.out.println(results.get(i).toString());
    }
  }
}


Check out the JavaDoc for the Hiberante Criterion Criteria package. It's good to know the various classes that are available to you. The Restrictions class is also a very popular tool for doing queries.

Happy Hibernating![/quote]

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.