createCriteria和createAlias之间的区别 [英] Difference between createCriteria and createAlias

查看:137
本文介绍了createCriteria和createAlias之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里阅读hibernate条件文件:

I was reading hibernate criteria document here:

http://docs.jboss.org/hibernate/orm/3.6/javadocs/org/hibernate/Criteria.html

我曾多次使用它,我通常使用 createAlias()来连接表,这里他们提供了两种方法来进行连接并从表中获取数据是:

I had used it many time and I am normally use createAlias() to join table, here they have provide two methods to make a join and fetch data from the tables, there are:

 List cats = session.createCriteria(Cat.class)
     .createCriteria("kittens")
         .add( Restrictions.like("name", "Iz%") )
     .list();

 List cats = session.createCriteria(Cat.class)
     .createAlias("kittens", "kit")
     .add( Restrictions.like("kit.name", "Iz%") )
     .list();

所以我无法区分 .createCriteria(kittens)之间的区别) createAlias(kittens,kit)或者可能是我没有得到这段代码的确切做法,有人可以帮助我清除我的困惑。

So I am not able to distinguish difference between .createCriteria("kittens") and createAlias("kittens", "kit") or may be I am not getting what this code exactly do, can someone help me to clear my confusion.

推荐答案


唯一的区别是 CreateCriteria 在没有alias参数的情况下还有2个额外的
重载,这个差异在
的最新版本中已经很久了。

The only difference is that CreateCriteria has 2 additional overloads without the alias parameter, this difference is long gone in the latest versions.

但基本上应用程序的使用量略有
CreateCriteria 使用它从父母到孩子的
映射关系,而 CreateAlias 你用你的自定义别名来定义

But essentially the application is slightly different in its usage is that CreateCriteria uses its relations of mapping from parent to child, whilst with CreateAlias you defined them with your customized alias names from the root.

这里

这篇关于createCriteria和createAlias之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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