我想從我的數據庫中刪除一些員工 但我不能。 這是我的倉庫代碼:在春季項目刪除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