How to cache results of a Spring Data JPA query method without using query cache?

The reason the code you have is not working is that @Cache is not intended to work that way. If you want to cache the results of a query method execution, the easiest way is to use Spring’s caching abstraction. interface PromotionServiceXrefRepository extends PagingAndSortingRepository<PromotionServiceXref, Integer> { @Query(“…”) @Cacheable(“servicesByCustomerId”) Set<PromotionServiceXref> findByCustomerId(int customerId); @Override @CacheEvict(value = “servicesByCustomerId”, … Read more

How do you handle with bulk deleting by an array of IDs in Spring Data JPA?

Just add the following to your user repository interface void deleteByIdIn(List<Integer> ids); Spring will automatically generate the appropriate query via method name derivation. https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods EDIT: A litte more detail on this Using Springs Repository interfaces like CrudRepository, JpaRespository brings the basic set of database operations, like create, read, update, delete, paging, sorting and so on. … Read more

Simultaneous use of Hibernate and Spring data jpa?

You need a single way of configuration you are now configuring both Hibernate and JPA. You should be using JPA for configuration so remove the hibernate setup. You are using Hibernate4 so you can take advantage of the, not so well known, HibernateJpaSessionFactoryBean of Spring. If you need access to the SessionFactory (which I assume … Read more

Can Spring Data REST’s QueryDSL integration be used to perform more complex queries?

I think you should be able to get this to work using the following customization: bindings.bind(user.dateOfBirth).all((path, value) -> { Iterator<? extends LocalDate> it = value.iterator(); return path.between(it.next(), it.next()); }); The key here is to use ?dateOfBirth=…&dateOfBirth= (use the property twice) and the ….all(…) binding which will give you access to all values provided. Make sure … Read more

What is the difference between query-methods find…By, read…By, query…By, and get…By in spring data?

EDIT: This answer covers Spring query creation mechanism described in docs If you are looking for the differences between concrete methods findById(..) vs getById(..) you can find nice desciption here (thanks to @smile comment) ORIGINAL ANSWER: I don’t know how about other subprojects, but for Spring Data JPA (1.10.2) these methods will work as aliases. … Read more

How To Configure MongoDb Collection Name For a Class in Spring Data

The only way you can currently achieve this is by annotating your domain class with @Document using the collection property to define the name of the collection instances of this class shall be persisted to. However, there’s a JIRA issue open that suggests adding a pluggable naming strategy to configure the ways class, collection and … Read more

How to shorten names of query methods in Spring Data JPA Repositories?

Use default Java 8 feature for wrapping, just like so: interface UserInterface extends JpaRepository<User, Long> { // use findOneByEmail instead User findOneByDeletedIsFalseAndEmail(String email); default User findOneByEmail(String email) { return findOneByDeletedIsFalseAndEmail(email); } } See an example. With Kotlin, you can use extension functions, for example: interface UserRepository : JpaRepository<User, Long> { // use findOneByEmail instead fun … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)