Spring data jpa- No bean named ‘entityManagerFactory’ is defined; Injection of autowired dependencies failed

Spring Data JPA by default looks for an EntityManagerFactory named entityManagerFactory. Check out this part of the Javadoc of EnableJpaRepositories or Table 2.1 of the Spring Data JPA documentation. That means that you either have to rename your emf bean to entityManagerFactory or change your Spring configuration to: <jpa:repositories base-package=”your.package” entity-manager-factory-ref=”emf” /> (if you are … Read more

Spring Boot & Spring Data: how are Hibernate Sessions managed?

I think I’ve found the answer myself. If somebody finds this question, here’s my answer. How does Spring manage Hibernate Sessions? By default, Spring Boot applies transaction management at the repository level. In this case, when calling a JpaRepository method (or in general any Repository method), Spring will: Ask the SessionFactory to create a new … Read more

Failed to start bean ‘documentationPluginsBootstrapper’ in spring data rest

I got same issue using springfox-swagger2 and springfox-swagger-ui version(3.0.0), spring-boot version(2.6.2) The way to resolve this issue is by adding pathmatcher in application. properties or application.yml for application.properties: spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER for application.yml: spring: mvc: pathmatch: matching-strategy: ant_path_matcher

How to sort by multiple properties in Spring Data (JPA) derived queries?

The trick is to simply delimit the properties you want to sort by using the direction keywords Asc and Desc. So what you probably want in your query method is something like: …OrderByProgDateAscStartTimeAsc Note, how we conclude the first property definition by Asc and keep going with the next property. Generally speaking, we recommend switching … Read more

Understanding the Spring Data JPA @NoRepositoryBean interface

The annotation is used to avoid creating repository proxies for interfaces that actually match the criteria of a repo interface but are not intended to be one. It’s only required once you start going into extending all repositories with functionality. Let me give you an example: Assume you’d like to add a method foo() to … Read more

When to use @RestController vs @RepositoryRestResource

Ok, so the short story is that you want to use the @RepositoryRestResource since this creates a HATEOAS service with Spring JPA. As you can see here adding this annotation and linking it to your Pojo you have a fully functional HATEOAS service without having to implement the repository method or the REST service methods … Read more

Spring Data Rest – Sort by multiple properties

Solution (tl;dr) When wanting to sort on multiple fields you simply put the sort parameter multiple times in the URI. For example your/uri?sort=name,asc&sort=numberOfHands,desc. Spring Data is then capable of constructing a Pageable object with multiple sorts. Explanation There is not really a defined standard on how to submit multiple values for a parameter in a … Read more