하나의 레코드를 mysql 5.1 db에 저장하려고합니다. 나는 (엔티티 manager.persist 사용) 또는() 메소드 다음도 DB에 레코드를 저장되지 않습니다 병합이 같은 기본 삽입 문을 사용하려고하면 경우는 예외에게로 던져JPA 쿼리가 예외를 throw합니다.
Query query = entityManager.createNativeQuery("insert into Employee(firstName,lastName,phone,email) values(?,?,?,?);");
query.setParameter(1, employee.getFirstName());
query.setParameter(2, employee.getLastName());
query.setParameter(3, employee.getPhone());
query.setParameter(4, employee.getEmail());
예외를 throw 위 쿼리는
org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.GenericJDBCException: could not execute native bulk manipulation query; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute native bulk manipulation query
도와주세요!
가 삽입 HQL 쿼리를 사용하지 마십시오
감사
당신은 아마 스택 트레이스의 중요한 부분을 생략하기 때문에 나는 즉시 쿼리와 함께 당신을 도울 수는 없지만
우리는 더 많은 stacktrace를 볼 수 있습니까? 당신이 쿼리에 대해 executeUpdate를 호출한다고 가정합니다. 왜 직원 인스턴스를 저장하는 것이 아니라면 jpa를 사용하고 있습니까? JPA의 핵심은 당신이하는 일을 할 필요가 없다는 것입니다. – hvgotcodes
그러면이 데이터를 어떻게 저장할 수 있습니까? entityManager.persist() 또는 merge()를 사용하려고하지만 데이터를 저장하지 않습니다. JPA없이 어떻게 저장할 수 있습니까? – user509755
완전한 예외와 스택 추적에 대한 Bozho의 요구 외에도'Employee' 클래스의 코드를 게시 할 수 있다면 도움이 될 것입니다. 특히 ID를 할당하는 방법, equals() 및 hashcode() 구현 , 정의한 고유 제한 조건 (있는 경우)이 있습니다. – Mopper