DATAJPA-137 - Fixed deleteAll() handling.
SimpleJpaRepository now deletes entities 1 by 1 for a call to deleteAll() to ensure the cascades get triggered. Introduced deleteAllInBatch() that contains the old behaviour.
This commit is contained in:
@@ -74,4 +74,9 @@ public interface JpaRepository<T, ID extends Serializable> extends PagingAndSort
|
||||
* @param entities
|
||||
*/
|
||||
void deleteInBatch(Iterable<T> entities);
|
||||
|
||||
/**
|
||||
* Deletes all entites in a batch call.
|
||||
*/
|
||||
void deleteAllInBatch();
|
||||
}
|
||||
|
||||
@@ -171,6 +171,18 @@ public class SimpleJpaRepository<T, ID extends Serializable> implements JpaRepos
|
||||
*/
|
||||
@Transactional
|
||||
public void deleteAll() {
|
||||
|
||||
for (T element : findAll()) {
|
||||
delete(element);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.jpa.repository.JpaRepository#deleteAllInBatch()
|
||||
*/
|
||||
@Transactional
|
||||
public void deleteAllInBatch() {
|
||||
em.createQuery(getDeleteAllQueryString()).executeUpdate();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -296,6 +295,19 @@ public class UserRepositoryTests {
|
||||
assertThat(repository.count(), is(0L));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-137
|
||||
*/
|
||||
@Test
|
||||
public void deleteAllInBatch() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
repository.deleteAllInBatch();
|
||||
|
||||
assertThat(repository.count(), is(0L));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests cascading persistence.
|
||||
*/
|
||||
@@ -443,16 +455,6 @@ public class UserRepositoryTests {
|
||||
Arrays.asList(firstUser, secondUser)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void executesMethodWithNamedParametersCorrectly() throws Exception {
|
||||
|
||||
firstUser = repository.save(firstUser);
|
||||
secondUser = repository.save(secondUser);
|
||||
|
||||
assertThat(repository.findByLastnameOrFirstnameUnannotated("Oliver", "Arrasz"), hasItems(firstUser, secondUser));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executesMethodWithNamedParametersCorrectlyOnMethodsWithQueryCreation() throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user