【问题标题】:HQL: Subquery returns more than 1 rowHQL:子查询返回多于 1 行
【发布时间】:2014-06-02 02:49:23
【问题描述】:

我是 HQL 新手,我需要有关此错误的帮助。

查询:

 String hqlsearchSelect =
                "select new com.eteligent.core.loans.paging.LoansAppCustomerPageItem("
                    + "main.loanno, (SELECT acct.id.clientid FROM LMSAccountInfo acct WHERE acct.loanno = main.loanno), (SELECT acct.name FROM LMSAccountInfo acct WHERE acct.loanno = main.loanno), main.acctsts, "
                    + "main.loanbal, (SELECT acct.matdt FROM LMSAccountInfo acct WHERE acct.loanno = main.loanno) )";

我认为查询无法确定它将返回哪条记录。

构造函数(LoansAppCustomerPageItem):

public LoansAppCustomerPageItem( final String acctNo, final String cifNo, final String customerName, final Integer acctStat, final BigDecimal acctBal, final Date acctDueDate )
{
    super();
    this.acctNo = acctNo;
    this.cifNo = cifNo;
    this.customerName = customerName;
    this.acctStat = acctStat;
    this.acctBal = acctBal;
    this.acctDueDate = acctDueDate;
}

【问题讨论】:

  • 关系映射是否正确?关系都是一对一的吗? LoansAppCustomerPageItem 类的构造函数是什么样的?
  • 这两个表之间没有关系,这就是我使用子查询的原因。我已经编辑了上面的帖子以包含构造函数。
  • HQL 不是这项工作的好工具。它旨在与映射实体一起使用。

标签: mysql sql subquery hql


【解决方案1】:

如果您只想从子查询中提取一行,请在子查询末尾使用LIMIT 1

【讨论】:

  • 我试过使用 LIMIT 但它给了我错误。我认为它从未在 HQL 中实现。有人说我应该使用 query.setMaxResults(),但它限制了我所有的结果。
猜你喜欢
  • 1970-01-01
  • 2018-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-15
  • 2013-08-18
相关资源
最近更新 更多