HQL-选择具有布尔参数的新构造函数

时间:2014-11-05 11:26:47

标签: java hibernate hql

我正在尝试使用布尔参数调用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')??

1 个答案:

答案 0 :(得分:2)

查询可能如下: -

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