I am trying to retrieve all rows where emailAccess is equal to john@yahoo.com
user table is structured this way
id | name | email | emailAccess
1 | john |john@yahoo.com | john@yahoo.com
2 | jeff |jeff@yahoo.com | john@yahoo.com
I have a log table like this
id | userId | message
1 | 1 | bla bla
2 | 2 | 1234
now I am using the following hql query to retrieve the log based on the userId where emailAccesss from sesssion is 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();
trying to use the above hql query gives me this error
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)
second stacktrace
Caused by: java.sql.SQLException: Subquery returns more than 1 row
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
Where am I failing. Kindly assist!
(FROM User u WHERE u.emailAccess = :emailAccess)
This returns more than one row and you have:
WHERE c.user =
You can't have an equals with multiple results on the right. Either change your query to return a single row or change to be something like:
WHERE c.user in
使用hql可以访问对象及其属性,请尝试以下查询:
String hql = "FROM Chat c WHERE c.user.emailAccess = :emailAccess"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.