Spring Data JPA: Query by Example?

This is now possible with Spring Data. Check out http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#query-by-example Person person = new Person(); person.setLastname(“Smith”); Example<Person> example = Example.of(person); List<Person> results = personRepository.findAll(example); Note that this requires very recent 2016 versions <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>1.10.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons</artifactId> <version>1.12.1.RELEASE</version> </dependency> see https://github.com/paulvi/com.example.spring.findbyexample

Spring data : CrudRepository’s save method and update

I wanted to know if the {save} method in CrudRepository do an update if it finds already the entry in the database The Spring documentation about it is not precise : Saves a given entity. Use the returned instance for further operations as the save operation might have changed the entity instance completely. But as … Read more

Isolated Controller Test can’t instantiate Pageable

Original answer: The problem with pageable can be solved by providing a custom argument handler. If this is set you will run in a ViewResolver Exception (loop). To avoid this you have to set a ViewResolver (an anonymous JSON ViewResolver class for example). mockMvc = MockMvcBuilders.standaloneSetup(controller) .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) .setViewResolvers(new ViewResolver() { @Override public View resolveViewName(String … Read more

Creating multiple aliases for the same QueryDSL path in Spring Data

You can create a transient property bound to QueryDSL this way: @Transient @QueryType(PropertyType.SIMPLE) public String getNameEndsWith() { // Whatever code, even return null } If you are using the QueryDSL annotation processor, you will see the “nameEndsWith” in the metadata Qxxx class, so you can bind it like any persisted property, but without persisting it.

How to correctly use PagedResourcesAssembler from Spring Data?

You seem to have already found out about the proper way to use but I’d like to go into some of the details here a bit for others to find as well. I went into similar detail about PagedResourceAssembler in this answer. Representation models Spring HATEOAS ships with a variety of base classes for representation … Read more

Is it problematic that Spring Data REST exposes entities via REST resources without using DTOs?

tl;dr No. DTOs are just one means to decouple the server side domain model from the representation exposed in HTTP resources. You can also use other means of decoupling, which is what Spring Data REST does. Details Yes, Spring Data REST inspects the domain model you have on the server side to reason about the … Read more

Disable Hypertext Application Language (HAL) in JSON?

(Hyper)media types The default settings for Spring Data REST use HAL as the default hypermedia representation format, so the server will return the following for the given Accept headers: No header -> application/hal+json -> HAL application/hal+json -> application/hal+json -> HAL application/json -> application/json -> HAL (this is what the default configures) application/x-spring-data-verbose+json -> application/x-spring-data-verbose+json -> … Read more