我想从我的数据库中删除一些员工 但我不能。 这是我的仓库代码:在春季项目删除JpaRepository
public interface EmployeRepository extends JpaRepository<Employe, Long> {
@Query("delete from Employe e where e.idEmploye=:x")
public Employe deleteEmploye(@Param("x") int idEmploye); }
这是我的控制器:
@RestController public class EmployeRestService {
@Autowired
private EmployeMetier EmployeMetier;
@RequestMapping(value="/employe3",method=RequestMethod.DELETE)
public Employe deleteEmploye(@RequestParam int idEmploye) {
return EmployeMetier.deleteEmploye(idEmploye);}}
当我测试控制器,我得到这个消息
{"timestamp": 1495688812536,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.dao.InvalidDataAccessApiUsageException",
"message": "org.hibernate.hql.internal.QueryExecutionRequestException: Not
supported for DML operations [delete from org.st.entities.Employe e where
e.idEmploye=:x]; nested exception is java.lang.IllegalStateException:
org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for
DML operations [delete from org.st.entities.Employe e where
e.idEmploye=:x]",
"path": "/employe3"
}
可以更改数据的查询[需要使用@ @修饰]注释(https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.modifying-queries)和'@ Transactional'。 – manish