您好,我想进行一个 hibarnate 查询,但在一个字段中我希望它是静态的或连续的字符串。 这是一个 sql 查询,相当于我要进行的 hibernate 查询
select sum(amount),sum(sales),"info" from products
对于 hibernate,我这样做了,但它不是那样工作的,这是我使用的查询:
session.createquery("select sum(amount),sum(sales),:info from Products")
.setParameter("info","information")
.list()
但它给了我 java.lang.NullPointerException 在 org.hibernate.hql.ast.ParameterTranslationsImpl.getNamedParameterExpectedType(ParameterTranslationsImpl.java:63) 有人可以帮助我吗,因为我所需要的只是映射中不存在的常量列。
我只想要一个这样的 hibernate 查询结果,例如:
==>12,145,information
==>123,345,information
==>5555,3456,information
==>9872,1023,information
最佳答案
只需执行与 SQL 中相同的操作。但是不要使用命名参数来传递常量。将其嵌入查询中:
session.createquery("select sum(amount), sum(sales), 'information' from Products").list()
不过,我看不到选择常量值的意义。
关于java - hibernate 查询中的固定字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30786621/