【问题标题】:HQL result not returning null DataHQL 结果不返回空数据
【发布时间】:2015-04-29 18:27:30
【问题描述】:

我有返回列表的 HQL 查询。

    Account_no, Account_name,Account_type,Account_date
    1             xyz          Saving       12/12/1982
    2             null          Recurring    null

HQL 在返回数据时没有给我空数据。

    Select * from Account_table
    return List = [0]= [[0]=1,[1]=xyz,[2]=Saving,[3]=12/12/1982]
                  [1]= [[0]=2,[2]=Recurring]

它没有返回空值。 请让我知道我需要更改什么才能获取所有可为空的数据。

【问题讨论】:

    标签: hibernate hql


    【解决方案1】:

    实际上,你已经为“Account_date”列设置了默认值,而 null 表示什么都没有(没有值),这就是它没有返回任何值的原因。

    【讨论】:

    • 没错,但它至少应该返回空值。如果我将过滤条件更改为左外连接,它也会返回空数据。
    【解决方案2】:

    如果您正在遍历您显示的数组数据,那么您应该会发现空值在那里。你在做这样的事情吗?

    // [0] = [[0]=1,[1]=xyz,[2]=Saving,[3]=12/12/1982]
    // [1] = [[0]=2,[2]=Recurring]
    
    for(int i = 0; i < results.length; i++) {
        MyAccount acct = new MyAccount();
        acct.setAccountNo((Integer) results[i][0]);
        acct.setName((String) results[i][1]); 
            // and so on
    }
    

    【讨论】:

      【解决方案3】:

      试试这个 -

      for(Object entity : list){
                      Object[] obj = (Object[]) entity;
                      MyAccount acct = new MyAccount();
                      acct.setAccount(obj[0]!=null ? obj[0].toString() : "do something else");
      }
      

      在“其他”部分做你的事情。

      【讨论】:

        猜你喜欢
        • 2017-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-13
        • 2012-10-21
        • 2013-08-13
        • 1970-01-01
        • 2013-01-01
        相关资源
        最近更新 更多