我想要的是:
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.
更多推荐
休眠选择所有投影组
发布评论