How to use Spring managed Hibernate interceptors in Spring Boot?

There’s not a particularly easy way to add a Hibernate interceptor that is also a Spring Bean but you can easily add an interceptor if it’s managed entirely by Hibernate. To do that add the following to your application.properties: spring.jpa.properties.hibernate.ejb.interceptor=my.package.MyInterceptorClassName If you need the Interceptor to also be a bean you can create your own … Read more

Spring Data Rest and Cors

Indeed, before Spring Data REST 2.6 (Ingalls) only HandlerMapping instances created by Spring MVC WebMvcConfigurationSupport and controllers annotated with @CrossOrigin were CORS aware. But now that DATAREST-573 has been fixed, RepositoryRestConfiguration now exposes a getCorsRegistry() for global setup and @CrossOrigin annotations on repositories are also recognized so this is the recommended approach. See https://stackoverflow.com/a/42403956/1092077 answer … Read more

kotlin data class + bean validation jsr 303

You need to use Annotation use-site targets since the default for a property declared in the constructor is to target the annotation on the constructor parameter instead of the getter (which will be seen by JavaBeans compliant hosts) when there are multiple options available. Also using a data class might be inappropriate here (see note … Read more

How to map Page to Page in spring-data-rest

You can still use the Page.map without lambda expressions: Page<ObjectEntity> entities = objectEntityRepository.findAll(pageable); Page<ObjectDto> dtoPage = entities.map(new Converter<ObjectEntity, ObjectDto>() { @Override public ObjectDto convert(ObjectEntity entity) { ObjectDto dto = new ObjectDto(); // Conversion logic return dto; } });

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

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

POSTing a @OneToMany sub-resource association in Spring Data REST

Assuming you already have discovered the post URI and thus the URI of the association resource (considered to be $association_uri in the following), it generally takes these steps: Discover the collection resource managing comments: curl -X GET http://localhost:8080 200 OK { _links : { comments : { href : “…” }, posts : { href … Read more

JSON parse error: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String value

You need jackson dependency for this serialization and deserialization. Add this dependency: Gradle: compile(“com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.4”) Maven: <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jsr310</artifactId> </dependency> After that, You need to tell Jackson ObjectMapper to use JavaTimeModule. To do that, Autowire ObjectMapper in the main class and register JavaTimeModule to it. import javax.annotation.PostConstruct; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; @SpringBootApplication public class MockEmployeeApplication { … Read more