【问题标题】:HQL- Select new constructor with boolean parametersHQL-选择带有布尔参数的新构造函数
【发布时间】:2014-11-05 20:30:44
【问题描述】:

我正在尝试使用布尔参数调用 testResultDTO 构造函数,但不断收到错误

TestResultDTO:

public class TestResultDTO extends AbstractDTO {

    private Boolean test;
    private Boolean locked;


    public TestResultDTO() {

    super();
    }


    public TestResultDTO(Boolean locked, Boolean test) {

    super();
    this.test = test;
    this.locked = locked;
    }

查询:

SELECT NEW com.xxx.model.dto.widgets.results.TestResultDTO(p.isLocked, IF((p.playerStatus = 'STANDARD'), false, true)) From player p Where p.id = 1

错误:

java.lang.NullPointerException
    at org.hibernate.internal.util.ReflectHelper.getConstructor(ReflectHelper.java:355) 

有没有办法传递一个硬编码的布尔参数('true')??

【问题讨论】:

  • 好吧,我认为你需要使用 0 或 1 来表示相同的值。试一次。
  • 试过了,还是一样的错误
  • 为什么你使用 new 然后你可以给字段而不是那个。
  • 这只是一个更大的构造函数的例子。我有几个更复杂的“如果”条件

标签: java hibernate hql


【解决方案1】:

查询可能是这样的:-

SELECT NEW com.xxx.model.dto.widgets.results.TestResultDTO(p.isLocked, CASE WHEN p.playerStatus = 'STANDARD' then false  else true end) From player p Where p.id = 1 .

供参考:http://docs.jboss.org/hibernate/core/3.5/reference/en/html/queryhql.html#queryhql-expressions

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 2019-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多