spring-data-jpa
으로 일괄 업데이트 (JPA 2.1
)를 수행하는 데 문제가 있습니다. 문서에 따르면스프링 데이터 jpa를 통한 일괄 업데이트
:
5.3.8. 쿼리 수정 위의 모든 섹션에서는 쿼리를 선언하여 지정된 엔터티 또는 엔터티 컬렉션에 액세스하는 방법을 설명합니다. 물론 Spring 데이터 저장소의 사용자 정의 구현에서 설명한 기능을 사용하여 사용자 정의 수정 동작을 추가 할 수 있습니다. 나는이 업데이트는있다 필요
@Modifying
@Query("update User u set u.firstname = ?1 where u.lastname = ?2")
int setFixedFirstnameFor(String firstname, String lastname);
그러나 개체를 :이 방법은 포괄적 인 사용자 정의 기능에 대한 가능하기 때문에, 당신은 실제로 단지 @Modifying으로 쿼리 방법을 주석으로 바인딩 매개 변수를 필요로 쿼리를 수정의 실행을 달성 할 수 @ManyToOne
다른 엔티티와의 관계.
@Entity
@Table(name = "usuarios", indexes = {
@Index(name = "idx_usuarios_rut", columnList = "rut")
,@Index(name = "idx_usuarios_email", columnList = "email")})
public class User extends BaseEntity implements UserDetails {
...
@NotNull(message = "Debe seleccionar un nivel")
@ManyToOne(fetch = FetchType.LAZY)
public Role getRole() {
return role;
}
}
그래서 내 UPDATE
입니다 :
@Modifying
@Transactional
@Query("update User u set u.password = ?2 where u.company = ?1 and u.role.name not in ('ROLE_ADMIN', 'ROLE_ROOT')")
int updatePasswordForAll(Company company, String password);
결과 네이티브 쿼리 update usuarios cross join set password=? where company_id=? and (nombre not in ('ROLE_ADMIN' , 'ROLE_ROOT'))
그래서 난 내가 잘못 뭐하는 거지 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual ...
를 얻을 수있다?
나는@Query("update User u set u.password = ?2 join u.role r where u.company = ?1 and r.name not in ('ROLE_ADMIN', 'ROLE_ROOT')")
으로 시도하지만이 사람은 나쁜 형성 업데이트 문장 org.hibernate.QueryException: node to traverse cannot be null! [update cl.arvisoft.mantenimiento.jpa.User u set u.password = ?2 join u.role r where u.company = ?1 and r.name not in ('ROLE_ADMIN', 'ROLE_ROOT')]
입니다.
감사합니다, =? 어디 company_id =? and (role_id in (role1_.id를 role1_에서 선택하십시오. 여기서 role1_.nombre는 ('ROLE_ADMIN', 'ROLE_ROOT'))가 아닙니다). – rvillablanca