I am using @SoftDelete and envers. I want to provide a feature that can show deleted data. I tried to show it using entity manager but it still adds the additional query. I need to use specification because i should also provide a feature to search the deleted data.
public List<BlogPost> getBlogPostAuditTrail(){
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<BlogPost> criteriaQuery = criteriaBuilder.createQuery(BlogPost.class);
Root<BlogPost> root = criteriaQuery.from(BlogPost.class);
criteriaQuery.where(BlogPostSpecification.byIsDeleted(true).toPredicate(root, criteriaQuery,criteriaBuilder));
Query query = entityManager.createQuery(criteriaQuery);
List<BlogPost> blogPosts = query.getResultList();
return blogPosts;
}
select
bp1_0.id,
bp1_0.content,
bp1_0.created_at,
bp1_0.is_deleted,
bp1_0.title,
bp1_0.updated_at
from
blog_post bp1_0
where
bp1_0.is_deleted=?
and bp1_0.is_deleted=false
i want to avoid the use of @Query on repository.