I have been testing out the delete feature for JpaRepository
and have this (simplified) Interface:
@Repository
public interface BrowserInfoDao extends JpaRepository<BrowserInfo, String> {
@Transactional
public Integer deleteByClientGuidAndBrowserGuid(String clientGuid, String browserGuid);
@Transactional
public Integer removeByClientGuidAndBrowserGuid(String clientGuid, String browserGuid);
}
In my tests I can't find any behavioral difference between the removeBy and deleteBy method. So my question is what is the difference between these if any? Is there a best practice reason to use one over the other?
Note: I am using Hibernate as the implementation.
Each of these defines its own functionality: CrudRepository provides CRUD functions. PagingAndSortingRepository provides methods to do pagination and sort records. JpaRepository provides JPA related methods such as flushing the persistence context and delete records in a batch.
Crud Repository doesn't provide methods for implementing pagination and sorting. JpaRepository ties your repositories to the JPA persistence technology so it should be avoided. We should use CrudRepository or PagingAndSortingRepository depending on whether you need sorting and paging or not.
JPA Repository is mainly used for managing the data in a Spring Boot Application. We all know that Spring is considered to be a very famous framework of Java. We mainly use this Spring Boot to create the Spring-based stand-alone and production-based applications with a very minimal amount of effort.
They are the same . Which one to choose depend on your personal preference.
For detail , please see this. Code-wise, check out PartTree which defines the following regex pattern for matching these delete query:
private static final String DELETE_PATTERN = "delete|remove";
private static final Pattern PREFIX_TEMPLATE = Pattern.compile( //
"^(" + QUERY_PATTERN + "|" + COUNT_PATTERN + "|" + DELETE_PATTERN + ")((\\p{Lu}.*?))??By");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With