Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The column name id was not found in this ResultSet

@Query(value = "SELECT s FROM logines.work_hour s WHERE TO_TIMESTAMP(s.start_time,  'YYYY-MM-DD HH24:mi')\\:\\:timestamp BETWEEN :start_time\\:\\:timestamp AND now()\\:\\:timestamp", nativeQuery = true)
List<WorkHour> findByStartTime(@Param("start_time") String startTime);

org.postgresql.util.PSQLException: The column name id was not found in this ResultSet.

What might be an issue?

like image 887
anduplats Avatar asked Oct 22 '25 03:10

anduplats


1 Answers

I got the same problem. It seems that in some scenarios the result columns can not be mapped to the output entity if we use table alias in SELECT statement.

SELECT t FROM my_table t WHERE ....;

The same query was working in one cases and failing in others. I found out that the problem goes away if we use a star * instead of the alias:

SELECT * FROM my_table t WHERE ...;
like image 188
user07 Avatar answered Oct 24 '25 17:10

user07



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!