Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JpaSpecificationExecutor.delete(…) and ….deleteAll(…) [DATAJPA-907] #1262

Closed
spring-projects-issues opened this issue May 31, 2016 · 3 comments
Assignees
Labels
in: core type: enhancement

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented May 31, 2016

SPT Developer opened DATAJPA-907 and commented

I have to delete massive entities. And I cannot add deleteByXxxxx(...) to repository by some reason. So, I implemented deleteAll(Specification) myself for general-purpose. I think it would be nice that JpaSpecificationExecutor has deleteAll(Specification) interface.

Please consider this.

Example for SimpleJpaRepository (Worked with transaction)

private EntityManager entityManager;
private Class<E> entityClass;

public int deleteAll(Specification<E> spec) {
	
	CriteriaBuilder builder = entityManager.getCriteriaBuilder();
	CriteriaDelete<E> query = builder.createCriteriaDelete(entityClass);
	
	Predicate predicate = spec.toPredicate(query.from(entityClass), null, builder);
	query.where(predicate);
	
	return entityManager.createQuery(query).executeUpdate();
}

2 votes, 3 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 31, 2016

Oliver Drotbohm commented

The reason that this is not implemented yet is that we're currently still JPA 2.0 compatible on the API level. ….createCriteriaDelete(…) was introduced in JPA 2.1. So with the introduction of the suggested method on JpaSpecificationExecutor we'd basically have to implement the method in a way that — if called on a JPA 2.0 EntityManager — would fail with a NoSucheMethodError. What also plays into this is that e.g. for OpenJPA, there's not even a JPA 2.1 compatible implementation available.

I am a bit torn here. Spring Framework 4 still supports Hibernate 3 versions, so I am assuming that there's a decent user base on Hibernate versions < 4.3 (the one that introduced JPA 2.1 support). I'll take this forward to the team and see what we can do

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 31, 2016

SPT Developer commented

I see. I expect future update. Thank you!

@spring-projects-issues spring-projects-issues added type: enhancement in: core labels Dec 30, 2020
@s-jepsen
Copy link

@s-jepsen s-jepsen commented Mar 3, 2021

Any plans on implementing this anytime soon?

gregturn added a commit that referenced this issue May 5, 2022
Introduce deleteAll(Specification) in JpaSpecificationExecutor.

See #1262.
gregturn added a commit that referenced this issue May 5, 2022
Ever since JPA 2.1, CriteriaBuilder has offer .createCriteriaDelete, returning a CriteriaDelete. With Spring Data JPA 3.0, rebased on JPA 3.0, we are able to guarantee this SPI, and hence rollout this feature.

See #1262.
gregturn added a commit that referenced this issue May 5, 2022
Ever since JPA 2.1, CriteriaBuilder has offered createCriteriaDelete, returning a CriteriaDelete. With Spring Data JPA 3.0 rebased on JPA 3.0, we are able to guarantee this SPI, and hence rollout support for this feature.

See #1262.
@gregturn gregturn self-assigned this May 5, 2022
@gregturn gregturn added this to the 3.0 M4 (2022.0.0) milestone May 5, 2022
gregturn added a commit that referenced this issue May 5, 2022
Ever since JPA 2.1, CriteriaBuilder has offered createCriteriaDelete, returning a CriteriaDelete. With Spring Data JPA 3.0 rebased on JPA 3.0, we are able to guarantee this SPI, and hence rollout support for this feature.

See #1262.
@gregturn gregturn closed this as completed May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: enhancement
Projects
None yet
Development

No branches or pull requests

4 participants