问题描述
我在这里阅读hibernate条件文件:
I was reading hibernate criteria document here:
我曾多次使用它,我通常使用 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
使用它从父母到孩子的
映射关系,而 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之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!