org.postgresql.util.PSQLException:查询未返回任何结果

Kam*_*ili 4 postgresql spring-boot

大家好我试图@Query在我的春季启动应用程序中使用注释在表中插入数据我得到一个postgres例外:

org.postgresql.util.PSQLException:  No results returned by the query 
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

这是存储库

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

这是控制器:

@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";
 }
Run Code Online (Sandbox Code Playgroud)

我在angularJs中使用$ http的这项服务

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

最后这是服务器日志

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.
Run Code Online (Sandbox Code Playgroud)

数据是正确的,我尝试相同的查询具有相同的值,它有效的原因posgres生成此异常,我怎么能修复,感谢任何帮助

Tur*_*uro 16

我认为修改查询必须额外注意

@Modifying
Run Code Online (Sandbox Code Playgroud)


小智 8

这应该可以解决您的问题:

@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);
Run Code Online (Sandbox Code Playgroud)

如果没有@Transactional 注解,可能会出现以下错误: javax.persistence.TransactionRequiredException: Executing an update/delete query