Questions tagged [spring-data-rest]

Spring Data REST (SDR) is a Spring Data project that aims to make it easy to expose Spring Data repositories as REST services. SDR use Spring HATEOAS internally to create HAL response.

2228 questions
28
votes
8 answers

Spring Data Rest base path

I have added Spring Data Rest (2.0) to an existing Spring MVC application by creating a Java config class that extends RepositoryRestMvcConfiguration, and adding @RestResource to the repositories. Is it possible to change the base URL for the Rest…
Jaffa
  • 501
  • 1
  • 8
  • 16
27
votes
5 answers

How to make an advanced search with Spring Data REST?

My task is to make an advanced search with Spring Data REST. How can I implement it? I managed to make a method to do a simple search, like this one: public interface ExampleRepository extends CrudRepository{ …
Alessandro C
  • 3,310
  • 9
  • 46
  • 82
27
votes
3 answers

Can I make a custom controller mirror the formatting of Spring-Data-Rest / Spring-Hateoas generated classes?

I'm trying to do something I think should be really simple. I have a Question object, setup with spring-boot, spring-data-rest and spring-hateoas. All the basics work fine. I would like to add a custom controller that returns a List in…
JBCP
  • 13,109
  • 9
  • 73
  • 111
25
votes
2 answers

Why is an excerpt projection not applied automatically for a Spring Data REST item resource?

I made a projection which should expose nested entities: @Projection(name = "inlineBusiness", types = { UserModel.class }) public interface InlineBusinessUserModelProjection { String getUsername(); String getFirstName(); String…
nKognito
  • 6,297
  • 17
  • 77
  • 138
25
votes
1 answer

Optionally disable HATEOAS format in Spring Data Rest

So let's say I have an existing application that has two endpoints /people and /pants. Calling GET /people returns: [ { "name":"john", "age":37, "pants":[ { "color":"green", …
Ben M
  • 1,833
  • 1
  • 15
  • 24
25
votes
2 answers

How do I avoid n+1 queries with Spring Data Rest?

Question. How do I avoid n+1 queries with Spring Data REST? Background. When querying Spring Data REST for a list of resources, each of the resulting top-level resources has links to the associated resources, as opposed to having the associated…
user41871
24
votes
5 answers

spring-data-rest integration test fails with simple json request

My spring-data-rest integration test fails for a simple json request. Consider the below jpa models Order.java public class Order { @Id @GeneratedValue// private Long id; @ManyToOne(fetch = FetchType.LAZY)// private Person creator; …
24
votes
6 answers

Select one column using Spring Data JPA

Does anyone have any idea how to get a single column using Spring Data JPA? I created a repository like below in my Spring Boot project, but always get the {"cause":null,"message":"PersistentEntity must not be null!"} error when accessing the…
Alax
  • 241
  • 1
  • 2
  • 3
23
votes
1 answer

Difference between @RestController and @RepositoryRestController

What is the typical use case code that shows the difference between those two annotations - meaning the @RestController and the @RepositoryRestController - ?
mCs
  • 2,591
  • 6
  • 39
  • 66
22
votes
3 answers

Hibernate DefaultEntityAliases raises NullPointerException

I'm using Spring Boot, Spring Data REST, Hibernate (5.2.12.Final) and I'm exposing my repositories as REST services. I've a problem with a query that raises a NullPointerException and I don't understand the reason. I'm calling this method via a HTTP…
drenda
  • 5,846
  • 11
  • 68
  • 141
22
votes
5 answers

Adding business logic to a spring-data-rest application

I have been experimenting with spring-data-rest (SDR) and am really impressed with how quickly I can build a rest api. My application is based around the following repository which gives me GET /attachements and POST /attachements package…
Richard Hensman
  • 550
  • 1
  • 6
  • 13
22
votes
4 answers

Spring data rest - Is there a way to restrict the supported operations?

I want to expose data from a database as Restful APIs in a Spring(SpringBoot) application. Spring Data Rest appears to be an exact fit for purpose for this activity. This database is read-only for my application needs. The default provides all the…
Manglu
  • 10,744
  • 12
  • 44
  • 57
21
votes
7 answers

Return IDs in JSON response from Spring Data REST

I've got an entity @Entity @Table(name = "books") public class Book { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String name; @Column(name = "id", unique = true, nullable = false) public…
lapots
  • 12,553
  • 32
  • 121
  • 242
21
votes
6 answers

Spring JPA REST sort by nested property

I have entity Market and Event. Market entity has a column: @ManyToOne(fetch = FetchType.EAGER) private Event event; Next I have a repository: public interface MarketRepository extends PagingAndSortingRepository { } and a…
uiii
  • 469
  • 1
  • 7
  • 19
21
votes
2 answers

spring data rest vs spring data jpa

I have had a look at the following question What are the advantages of using Spring Data REST over Spring Data JPA? It doesn't quite cater to my needs. My DB is on MYSQL, I chose Spring-Data-JPA implementation. What are all the added advantages that…
Dipanshu Verma
  • 459
  • 3
  • 8
  • 22