0

using spring jpa.

the repository:

public interface FacultyMemberImpl extends JpaRepository<FacultyMember,Long> {

    @Query("SELECT e FROM FacultyMember e WHERE e.name =:name")
    List<FacultyMember> getFacultyByName(@Param("name") String name);

    @Transactional
    @Modifying
    @Query("UPDATE FacultyMember e SET e.name=:name, e.department=:department WHERE e.id=:id")
    List<FacultyMember> updateFaculty(@Param("id") int id,@Param("name") String name,@Param("department") String department);
}

the error

2019-01-28 09:57:53.027 ERROR 14264 --- [nio-8181-exec-7] 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.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [UPDATE com.facultyProject.faculty_project.dao.FacultyMember e SET e.name=:name, e.department=:department WHERE e.id=:id]; nested exception is java.lang.IllegalStateException: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [UPDATE com.facultyProject.faculty_project.dao.FacultyMember e SET e.name=:name, e.department=:department WHERE e.id=:id]] with root cause
João Menighin
  • 3,083
  • 6
  • 38
  • 80
dishank goyal
  • 105
  • 1
  • 4
  • 16
  • Can you add importations? the first impression, you were trying to modifying a record in database which you have to mark it as @Transactional as well as Modifying, in order to say Spring that it can modify existing records. but with updating that you did, looks like your importations are wrong – Jonathan JOhx Jan 28 '19 at 15:58
  • According to https://stackoverflow.com/questions/44022076/jparepository-not-supported-for-dml-operations-delete-query the method should return void otherwise the exception keeps getting thrown. You could try that. – Sanketh Jan 28 '19 at 15:58
  • Possible duplicate of [JpaRepository Not supported for DML operations \[delete query\]](https://stackoverflow.com/questions/44022076/jparepository-not-supported-for-dml-operations-delete-query) – Sanketh Jan 28 '19 at 16:40

0 Answers0