0

The query I use for a JDBCPagingItemReader in my Spring Batch project is:

 SELECT
  account_login_log_id log_id,
  created_at reference_time 
 FROM account_login_log 
 WHERE account_login_log_id > 1000 
 ORDER BY account_login_log_id

And a RowMapper catches items got from the reader and makes a Object named say, SomeGeneralLog.

    SomeGeneralLog log = new SomeGeneralLog();
    log.setLogId(rs.getInt("log_id");
    log.setReferenceTime(rs.getTimestamp("reference_time");

and, return this log to a writer, as some Batch processes do.

Here's the point. The program throws SQLException! java.sql.SQLException: Column 'account_login_log_id' not found.

What? I didn't even make it to find the column 'account_login_log_id' in RowMapper code. Actually, I could make it run anyway by replacing the column name in ORDER BY clause with 'log_id'. But why? What was the reason? Please make any notes as much as you could imagine. (I suspect the order of query processing by keywords in query. *ref: https://stackoverflow.com/a/31808872/3648833)

Thanks.

Community
  • 1
  • 1
choiapril
  • 183
  • 1
  • 4
  • 14

1 Answers1

1

SELECT account_login_log_id log_id

You gave the column an alias, so now it has a new name, and you have to use that new name.

Your exact mileage may vary between RDBMS.

Thilo
  • 257,207
  • 101
  • 511
  • 656