gpt4 book ai didi

java - createCriteria 和 createAlias 的区别

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:48:34 26 4
gpt4 key购买 nike

我在这里阅读 hibernate 标准文档:

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

我用过很多次,我通常使用createAlias()来连接表,这里他们提供了两种方法来连接和从表中获取数据,有:

 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") 之间的区别,或者我可能不是了解这段代码的确切作用,有人可以帮助我消除困惑。

最佳答案

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

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.

阅读更多 here .

关于java - createCriteria 和 createAlias 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18062286/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com