休眠选择所有投影组

编程入门 行业动态 更新时间:2024-10-24 14:19:17
本文介绍了休眠选择所有投影组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在hibernate Criteria规范中,如果我想在表中分组属性,我必须使用Projections.groupProperty。问题是我无法选择表中的所有字段。

我想要的是:

SELECT * FROM实体GROUP BY字段

如果我在hibernate Criteria中使用group,那么groupProperty必须存在,并且sql结果将为: SELECT字段FROM实体GROUP BY字段。

有什么方法可以获得我想要的吗?我在CriteriaJoinWalker的hibernate代码中看到,当我想选择全部(select *)时,代码已经指定是否有投影。我的假设,如果我想改变行为,我必须改变CriteriaJoinWalker代码。我可以修改代码,也许我可以得到我想要的结果,但如果可以的话,我不希望覆盖我的项目的hibernate核心代码。

// CriteriaJoinWalker if(translator.hasProjection() )) { resultTypes = translator.getProjectedTypes(); initProjection(translator.getSelect(),translator.getWhereCondition(),translator.getOrderBy(),translator.getGroupBy(),LockMode.NONE); } else { resultTypes =(new Type [] { TypeFactory.manyToOne(persister.getEntityName())}); initAll(translator.getWhereCondition(),translator.getOrderBy(),LockMode.NONE);

谢谢解决方案

如果您使用Projections,那么您将无法获得整体的实体对象。不幸的是,冬眠不能帮助你。查看此问题,并查看此线程。

In hibernate Criteria specification, if I want to group property in table, I must use Projections.groupProperty. The problem is I can't select all the field in the table.

What I want to is:

SELECT * FROM entity GROUP BY field

If i use group in hibernate Criteria, then the groupProperty must be exist, and the sql result will be: SELECT field FROM entity GROUP BY field.

Is there any way to get what I want? I see in hibernate code, in CriteriaJoinWalker, when I want to select all (select *), the code is already specify if there is projection or not. My assumption if I want to change the behavior, I must change the CriteriaJoinWalker code. I can modify the code, and maybe I can get the result what I want, but if I can, I do not want to override the hibernate core code to my project. Is there any way to change it directly without change hibernate code?

// CriteriaJoinWalker if(translator.hasProjection()) { resultTypes = translator.getProjectedTypes(); initProjection(translator.getSelect(), translator.getWhereCondition(), translator.getOrderBy(), translator.getGroupBy(), LockMode.NONE); } else { resultTypes = (new Type[] { TypeFactory.manyToOne(persister.getEntityName()) }); initAll(translator.getWhereCondition(), translator.getOrderBy(), LockMode.NONE); }

Thanks

解决方案

If you use Projections then you will not be able to get an Entity object as a whole. Unfortunately hibernate cant help you. Check out this Issue and also check out this thread.

更多推荐

休眠选择所有投影组

本文发布于:2023-10-24 17:19:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524538.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!