Karthick Raj
Karthick Raj

Reputation: 299

Could not extract ResultSet When i using Native Query in Spring Jpa

I am trying to get true or false, with some compare condition using Spring JPA native query. But I got following Exception,

could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

The query I am trying is:

SELECT case when ABS(am_savedagent.AGENT_VERSION)< 1.8 then 'true' else 'false' end as bool 
FROM am_savedagent where am_savedagent.BOX_ID="ots-JIO6Yn0jZbxs";

My Repository

public interface SavedAgentRepository extends JpaRepository<SavedAgentDetails, String>, JpaSpecificationExecutor<SavedAgentDetails> {
    @Query(value = "SELECT case when ABS(SavedAgentDetails.agentVersion)< ?1 then 'true' else 'false' end as bool FROM SavedAgentDetails where SavedAgentDetails.boxId=?2", nativeQuery = true)
    public Optional<List<Object>> findByAgentVersionAndBoxId(String currentVersion, String boxid);
}

I can't find y the Errors Comming. please help me, someone.

Upvotes: 0

Views: 5589

Answers (1)

Ankit Gupta
Ankit Gupta

Reputation: 26

Since you are using native query =true, that's why you need to use the table name and not the entity name inside your query.

Try this -->

public interface RegisterAgentRepository extends JpaRepository<RegisterAgentDetails, String>, JpaSpecificationExecutor<RegisterAgentDetails> {
    @Query(value = "SELECT case when ABS(am_registeragent.AGENT_VERSION)< ?1 then 'true' else 'false' end as bool FROM am_registeragent where am_registeragent.SAASBOX_ID=?2", nativeQuery = true)
    public Optional<List<Object>> findByAgentVersionAndSaasboxId(String currentVersion, String saasboxid);
}

Upvotes: 1

Related Questions