The column name id was not found in this ResultSet - spring-boot

#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?

The issue could be due to the usage of only s in #Query. replacing s with all db column names with it i.e., s.coloumn1, s.column2, s.column3 will fix the issue.

Related

Spring MVC, Select Special Columns in Native SELECT Query

this is my native SELECT Query in Repository
#Modifying
#Query(value = "SELECT * FROM tasks WHERE title LIKE '%Java%' ORDER BY id DESC ", nativeQuery = true)
List<Task> listAllTasks();
this works ok, but when I use custom column name instead of *, like this
#Modifying
#Query(value = "SELECT title FROM tasks WHERE title LIKE '%Java%' ORDER BY id DESC ", nativeQuery = true)
List<Task> listAllTasks();
I have this error :
org.postgresql.util.PSQLException: The column name id was not found in this ResultSet.
any Help?
The resultset doesn't have the "id" in it, you have to provide it.
You should change the way you are declaring your SQL:
SELECT t.title, t.id FROM tasks t WHERE t.title LIKE '%Java%' ORDER BY t.id DESC
Check out this sort example:Native Queries
Select * from Entity -> returns a List of Entity
Example:
#Query(select * from tasks)
List<Task> findAllTasks();
Select column from Entity -> returns a List of Types of the entity.
Example:
#Query(select t.title from tasks t)
List<String> findTitle_AllTasks();
title is of the type String
Select multiple columns from Entity -> returns an Object[] holding the data
Example:
#Query(select t.id, t.title from tasks t)
List<Object[]> findIdTitle_AllTasks();
So, you are retrieving String type data - title and asking to return a List of Task type. This is causing the problem. You can actually check the hibernate docs under HQL and JPQL to understand this.
Plus, you are doing a SELECT (DQL operation). #Modifying is rudimentary here as it is used for DML operations using Data JPA - UPDATE/DELETE.

jhipster : unable to select specific columns

when i select 4 column an error occur :
Caused by: org.postgresql.util.PSQLException: The column name id was not found in this ResultSet.
#Query(value = "select name,rating,numberofviews,status from learningunit", nativeQuery = true)
List<Learningunit> findAllData();
then i add id to the query and the same error occur with different column and so on
#Query(value = "select id,name,rating,numberofviews,status from learningunit", nativeQuery = true)
List<Learningunit> findAllData();
Caused by: org.postgresql.util.PSQLException: The column name summary
was not found in this ResultSet.
notes:i using jhipster and ever entity has a dto and mapper
entity
DTO
Mapper
finally i solved the problem using this query #Query(value = "select null as id , name,rating,numberofviews,null as status from learningunit", nativeQuery = true)
the point is to select null as the name of your column

Using JDBC prepared statement with where clause for Apache Pheonix

I am new to HBase and using Pheonix to query HBase. I am using below query with where condition . It is displaying undefined Column when running this query. Please look into thsi and help me with solution I am using exact column names present in table
PreparedStatement ps = connection.prepareStatement("select * from event_time where name = ? and process = ? and location = ? limit 10");
ps.setString(1,"myfirstServer");
ps.setString(2,"1stEvent");
ps.setString(3,"Chennai");
I am getting error undefined column "process" . It is working when I pass only single column name ("select * from event_time where name = ? limit 10")

how to update only few columns of a table in spring jdbc template

i am using spring jdbc template and i want to update some of the columns in a table.
Ex:Consider Student table
id-->1007.
name-->Krish.
age-->25.
tel-->0112538956536.
this is a existing record.i want to update some fields only(updating fields change time to time).others should have their existing values.how can i acheive this in Spring JDBC template.Any suggestions will be very much helpful.
Thanks.
you can use jdbc template for update table from application
here is the simple example
String name = "asdads";
int age = 12;
String tel = "+905655465465";
int id = 1;
String SQL = "update Student set name = ?, age= ? ,tel=?, last_updated = sysdate() where id = ?";
jdbcTemplate.update(SQL,name, age, tel, id);
may be just like
jdbcTemplate.update(
"update Student set last_updated=now(),some_field=?",
"some value");

JPA QueryDSL: count() leads to ORA-01722: invalid number

I have the following Query, which tries to find the count of all RUNNING Trackings:
new JPAQuery(getEntityManager()).from(myTracking)
.where(myTracking.trackingStatus.isNotNull(),
myTracking.trackingStatus.eq(TrackingStatus.RUNNING))
.count()
This leads to ORA-01722: invalid number. Why?
EDIT: Logging of the SQL statement:
/* select
count(myTracking)
from
MyTracking myTracking
where
myTracking.trackingStatus is not null
and myTracking.trackingStatus = ?1 */ select
count(mytrackin0_.ID) as col_0_0_
from
owner.T_my_TRACKING mytrackin0_
where
(
mytrackin0_.STATUS is not null
)
and mytrackin0_.STATUS=?
The solution is I forgot to add the #Enumerated(EnumType.STRING) to my Enum attribute.
MyEntity{
#Enumerated(EnumType.STRING)
private TrackingStatus trackingStatus;
}
This was resulting in the Enum-Position and NOT the Enum-String beeing inserted into the Database-Column.
Once I added the annotation the still running trackings in the database were compared with their Enum-Position to the Enum-String from the query -> ORA-01722: invalid number.
The solution was to delete/migrate the few wrong mapped trackings.

Resources