[英]Caused by: java.sql.SQLException: Subquery returns more than 1 row on all rows where emailAccess is thesame
我正在嘗試檢索emailAccess等於john@yahoo.com的所有行
用戶表的結構是這樣的
id | name | email | emailAccess
1 | john |john@yahoo.com | john@yahoo.com
2 | jeff |jeff@yahoo.com | john@yahoo.com
我有一個這樣的日志表
id | userId | message
1 | 1 | bla bla
2 | 2 | 1234
現在我正在使用以下hql查詢來檢索基於userId的日志,其中來自sesssion的emailAccesss為john@yahoo.com
String hql = "FROM Chat c WHERE c.user = (FROM User u WHERE u.emailAccess = :emailAccess)";
return _sessionFactory.getCurrentSession().createQuery(hql).setParameter("emailAccess", emailAccess).list();
嘗試使用上面的hql查詢給我這個錯誤
Caused by: org.hibernate.exception.DataException: could not extract ResultSet
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:135)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
第二個堆棧跟蹤
Caused by: java.sql.SQLException: Subquery returns more than 1 row
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
我在哪里失敗。 請協助!
(FROM User u WHERE u.emailAccess = :emailAccess)
這將返回多行,並且您具有:
WHERE c.user =
您不能在右側獲得多個結果的均等值。 更改查詢以返回單行或更改為類似以下內容:
WHERE c.user in
使用hql可以訪問對象及其屬性,請嘗試以下查詢:
String hql = "FROM Chat c WHERE c.user.emailAccess = :emailAccess"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.