sql异常:查询中没有列时找不到列

wkftcu5l  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(506)

我试图在java应用程序中运行一个查询,但它抛出了一个异常,我将很快粘贴stacktrace。当我在mysql终端上运行相同的查询时,它运行得非常好。但当javax持久性出现时,它就崩溃了。

  1. Query query = entityManager.createNativeQuery(myQuery);
  2. List<String> resultList = query.getResultList();

这是我得到的例外。

  1. java.sql.SQLException: Column 'id' not found.
  2. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
  3. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
  4. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
  5. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
  6. at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1144)
  7. at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2813)
  8. at org.hibernate.type.IntegerType.get(IntegerType.java:28)
  9. at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
  10. at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:189)
  11. at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:474)
  12. at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:420)
  13. at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:317)
  14. at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
  15. at org.hibernate.loader.Loader.doQuery(Loader.java:701)
  16. at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
  17. at org.hibernate.loader.Loader.doList(Loader.java:2213)
  18. at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
  19. at org.hibernate.loader.Loader.list(Loader.java:2099)
  20. at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
  21. at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
  22. at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
  23. at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
  24. at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:65)

以下是查询:

  1. select uqd.id as requestId,count(*) as dailyRunCount,sum(finalTab.diffInMinutes) as totalRunningTimeInMinutes,config_level,user_email_id,team_name, description,cast(sum(finalTab.diffInMinutes) * 3.35 as decimal(10,2)) as cost from user_query_details uqd join (select a.request_id,(b.state_change_time_stamp - a.state_change_time_stamp)/60000 as diffInMinutes from (select request_id,job_id,state_change_time_stamp from user_request_history where state = 'RUNNING' and state_change_time_stamp >= (UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY)*1000)) a join (select job_id,state_change_time_stamp from user_request_history where state ='COMPLETED') b on a.job_id = b.job_id) finalTab on uqd.id=finalTab.request_id where uqd.discriminator='S' and query is not null and config_level='LEVEL_TWO' group by uqd.id order by totalRunningTimeInMinutes desc limit 3

任何帮助都将不胜感激。谢谢。

qvk1mo1f

qvk1mo1f1#

已更改的查询

  1. SELECT
  2. uqd.id as requestID,count(*) as dailyRunCount,
  3. sum(finalTab.diffInMinutes) as totalRunningTimeInMinutes,
  4. config_level,user_email_id,team_name,
  5. description,
  6. cast(sum(finalTab.diffInMinutes) * 3.35 as decimal(10,2)) as cost
  7. FROM
  8. user_query_details uqd join
  9. (SELECT
  10. a.request_id,
  11. (b.state_change_time_stamp - a.state_change_time_stamp)/60000 as diffInMinutes
  12. FROM
  13. (SELECT
  14. request_id,job_id,state_change_time_stamp
  15. FROM
  16. user_request_history
  17. WHERE
  18. state = 'RUNNING' and
  19. state_change_time_stamp >= (UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY)*1000)) a join
  20. (select job_id,state_change_time_stamp from user_request_history where state ='COMPLETED') b on a.job_id = b.job_id) finalTab on uqd.id=finalTab.request_id where uqd.discriminator='S' and query is not null and config_level='LEVEL_TWO' group by requestID order by totalRunningTimeInMinutes desc limit 3
展开查看全部

相关问题