按特定列选择不同的实体
我有一个包含 4 列的表:id、column_a 和 column_b
我的初始查询基本上是
Session session = initialize my hibernate session;
Criteria criteria = session.createCriteria(MytableBean.class);
// add some constraints
return criteria.list()
它返回一些结果,例如:
id | column_a | column_b |
1 | A | 1 |
2 | A | 1 |
3 | A | 2 |
4 | B | 3 |
5 | B | 3 |
但我不想多次获得相同的一对(column_a,column_b),即使我需要它在我的数据库中出现过很多次。
因此,我正在寻找一个返回类似于以下结果的查询:
id | column_a | column_b |
| A | 1 |
| A | 2 |
| B | 3 |
在 sql 中,我将使用 SELECT DISTINCT column_a, column_b FROM ....
但我不能使用 sql (并且要么不'不想尽可能使用hql)。
I have a table with 4 columns : id, column_a and column_b
My initial query is basicaly
Session session = initialize my hibernate session;
Criteria criteria = session.createCriteria(MytableBean.class);
// add some constraints
return criteria.list()
And it returns some results like :
id | column_a | column_b |
1 | A | 1 |
2 | A | 1 |
3 | A | 2 |
4 | B | 3 |
5 | B | 3 |
But I don't want to get several times the same couple (column_a, column_b), even if I need to have it many times in my database.
So, I'm looking for a query which returns a result similar to:
id | column_a | column_b |
| A | 1 |
| A | 2 |
| B | 3 |
In sql I would use SELECT DISTINCT column_a, column_b FROM ....
But I can't use sql (and either don't want to use hql, as far as possible).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面将实现这一点。将返回 Object[] 列表。
The following will accomplish this. A list of Object[] will be returned.