2017-06-18 15 views
1

イム私のJPAリポジトリを更新しようと更新クエリ

@Transactional 
public interface UserRepository extends JpaRepository<User, Integer> { 
User findByUsername(String username); 
User findById(Long id); 
@Query(value = "update user t set t.rule_id = NULL where t.rule_id = :id", nativeQuery = true) 
List<User> setNUll(@Param("id") String id);} 

これは私のコントローラの一部です:

@RequestMapping(value = "/admin/rule/{id}/edit", method = RequestMethod.GET) 
public String editRule(@PathVariable Integer id, Model model) 
{ 
    userService.setNUll(Integer.toString(id)); 
    model.addAttribute("rule", ruleCrudService.getRuleById(id)); 
    updateUserData(); 
    return "ruleForm"; 
} 

そして、このエラーが私のブラウザでapears:

There was an unexpected error (type=Internal Server Error, status=500). could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet

サーバーには次のように記載されています。

SQL Error: 0, SQLState: S1009 2017-06-18 12:51:15.778 ERROR 10388 --- [nio-8080-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper : Can not issue data manipulation statements with executeQuery(). 2017-06-18 12:51:15.844 ERROR 10388 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet] with root cause

java.sql.SQLException:executeQuery()でデータ操作文を発行できません。

答えて

1

上記の@Modifyingの注釈を@Queryにすると、JPAを使用して更新クエリを表示する必要があります。