2

I am using a JpaRepository for my ORM.

@Entity
@DiscriminatorValue(value = "L")
@Table(name = "LARGEPROJECT")
public class LargeProject extends Project {

LargeProject() { // jpa only
}

public String description;

@ElementCollection
public Map<String, String> params = new HashMap<>();

@ElementCollection
public Map<String, String> anotherSet = new HashMap<>();

}

I am trying to do a batch delete using the following api: this.largeProjectRepository.deleteAllInBatch();

public interface LargeProjectRepository extends JpaRepository<LargeProject, Long> {
}

I am getting an exception of the form:

org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint ["FK_K8XLJ5LKC9IK2E39EK06MWUM7: PUBLIC.LARGE_PROJECT_PARAMS FOREIGN KEY(LARGE_PROJECT_PROJECT_ID) REFERENCES PUBLIC.LARGEPROJECT(PROJECT_ID) (1)"; SQL statement: delete from largeproject where (project_id) IN (select project_id from HT_largeproject) [23503-176]];

I have researched a bit and found the following: How to do bulk delete in JPA when using Element Collections?

How can I cascade delete a collection which is part of a jpa entity?

I am wondering if API based delete is not supported by JPA as stated in these posts for @ElementCollection? If not what is the best way to do this?

Community
  • 1
  • 1
Tuhin Kanti Sharma
  • 1,056
  • 2
  • 8
  • 19
  • I see that bulk delete deleteAllInBatch() does work and creates statements of the form `delete from largeproject where (project_id) IN (select project_id from project).` This works for empty element collection as expected but is an incorrect statement if elementcollection has records since each element collection should be deleted first to not violate the FK integrity constraint – Tuhin Kanti Sharma May 09 '16 at 17:00

0 Answers0