Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.postgresql.util.PSQLException: No results returned by the query

hey everyone am trying to insert data in a table using @Query annotation in my spring boot app am getting a postgres Exception :

org.postgresql.util.PSQLException:  No results returned by the query 

this is my code :

this is the repository

@Query(value="INSERT INTO \"FCT_BY_DEV\"(\"IdDev\", \"IdFonction\") VALUES (?, ?) ",nativeQuery=true)
public String isertfonctionstodev(int dev,int fonction);

this is the controller :

@RequestMapping(value="/function/insert", method = RequestMethod.POST)
public String insererfonctions (int dev,int fonction){
    System.out.println("dev="+dev+"fonction="+fonction);
     fonctionRepository.isertfonctionstodev(dev, fonction);
     System.out.println("********");
     return "aaa";
 }

am using this service by $http in angularJs

$http.post("/function/insert?dev="+$scope.id+"&fonction="+$scope.idf);

and finaly this is the server log

dev=16006fonction=14
Hibernate: INSERT INTO "FCT_BY_DEV"("IdDev", "IdFonction") VALUES (?, ?) 
 2016-04-27 16:52:03.204  WARN 7036 --- [nio-8080-exec-2]    o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 02000
 2016-04-27 16:52:03.204 ERROR 7036 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : Aucun résultat retourné par la requête.

the data is correct and i tried the same query with the same value and it worked why posgres is generating this exception and how can i fixed , thanks to any help

like image 361
Kamel Mili Avatar asked Apr 27 '16 16:04

Kamel Mili


2 Answers

I think modifying queries must be annotared with an extra

@Modifying
like image 93
Turo Avatar answered Oct 10 '22 07:10

Turo


This should solve your issue:

@Transactional
@Modifying(clearAutomatically = true)
@Query(value="update policy.tbl_policy set ac_status = 'INACTIVE' where pol_id = :policyId and version_no = :version_no and ac_status = 'ACTIVE'", nativeQuery=true)
public void updateExistingRowbyId(@Param("policyId") Long pol_id, @Param("version_no") Long version_no);

Without @Transactional annotation, following errors may occur: javax.persistence.TransactionRequiredException: Executing an update/delete query

like image 21
AritraDB Avatar answered Oct 10 '22 08:10

AritraDB