将以下标准转换为HQL [英] Conversion of below criteria into HQL

查看:95
本文介绍了将以下标准转换为HQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下条件,请告知如何将以下条件转换为HQL,因为我想使用HQL

I have the following criteria please advise how can I convert the below criteria into HQL , as I want to use HQL

public List<tttBook> findtooks() {

            List<tttBook> tooks =null;
            Criteria criteria = session.createCriteria(tttBook.class);
            ProjectionList proList = Projections.projectionList();
            proList.add(Projections.property("Id"));
            proList.add(Projections.property("longName"));
            tooks = criteria.list();
            return tooks;

        }

也请在上述标准中告知我有什么问题因为现在它正在获取对象的所有属性,所以需要很多时间,我认为我的投影实现存在问题。

also please let me know in this above criteria what is wrong since right now it is fetching all the attributes of the object and it takes lots of time i think there is something wrong with my projections implementation.

推荐答案

您可以在对象 tttBook 中创建另一个构造函数。您还应该遵循命名约定,并以大写字母开头和以小写字母开头的属性来调用类。

You can create another constructor in your object tttBook. Also you should follow naming convention and call class starting with capital letter and properties with small letter.

package yourpath;

public class TttBook {
   private Long id;
   private String longName;

   public TttBook(Long id, String longName) {
      this.id = id;
      this.longName = longName;
   }

   // getters, setters
}

查询

List<TttBook > list = (List<TttBook >) session.createQuery("select 
   new yourpath.TttBook(id, longName) from TttBook").list();

这篇关于将以下标准转换为HQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆