Hibernate标准:如何按两列串联排序?
我有一个 Person 表,其中有两列:名字和姓氏。 Person 类有两个相应的字段:firstName 和lastName。现在我正在使用 criteria api 并尝试根据连接的这两列创建订单。是否可以?还是只能通过hql来实现?
I have a Person table which has two columns: first_name and last_name. The Person class has two corresponding fields: firstName and lastName. Now I'm using criteria api and trying to create an order by based on these two columns concatenated. Is it possible? Or it can only be achieved by hql?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是 JBoss 休眠站点 的示例:
或者从同一网站,获取 Criteria api:
JBoss 的人似乎很喜欢猫。
Here an example for the JBoss hibernate site:
Or from the same website, for the Criteria api:
They seem to be quite fond of cats at JBoss.
我遇到了同样的问题,并且 criteria api orderBy 方法不适用于连接列。我需要将此与 criteriaBuilder.construct() 方法一起使用。我通过扩展 Orale10gDialect 类并注册自定义函数解决了这个问题:
然后:
...
当然,您还必须选择这个串联列。
I had the same problem and criteria api orderBy method won't work with concatenated columns. I needed this to use with criteriaBuilder.construct() method. I solved this by extending Orale10gDialect class and registering custom function:
And then:
...
Of course you must also select this concatenated columns.