spring-data-rest

findBy URI not working in Spring Data Rest

╄→尐↘猪︶ㄣ 提交于 2019-12-11 10:21:43
问题 By default, in Spring Data Rest the @Id of the entity is not exposed. In line with the REST rules, we're supposed to use the URI of the resource to refer to it. Given this assumption, the findBy queries should work if you pass a URI to them, but they don't. For example, say I have a one-to-many relationship between Teacher and Student. I want to find students by teacher. List<Student> findByTeacher(Teacher teacher) http://localhost:8080/repositories/students/search/findByTeacher?teacher=http:

Why does @RepositoryRestController do not have @ResponseBody annotation like @RestController?

梦想的初衷 提交于 2019-12-11 09:54:40
问题 I'm using Spring-data-rest and wondering if there is a reason behind the fact that @RestController also has @ResponseBody but @RepositoryRestController has not. 回答1: All controllers in Spring Data REST using that annotation return a ResponseEntity<T> anyway, so that technically @ResponseBody is not needed. We generally prefer ResponseEntity as return type for two reasons: In controller methods serving REST requests, you usually want to control details of the response (headers, the status code

Can i offer an endpoint in parallel to a spring-data-rest GET?

99封情书 提交于 2019-12-11 08:44:52
问题 my project is moving away from a custom json format to json-hal and spring-data-rest. to continue the support for the "old" json i want to run the existing Resource-Controller parallel to the new Spring-Data-Rest provided one. Whenever i configure spring-data-rest to use the same url as our existing controller ONLY the old controller is used and if the accept-header does not match i get an error response. when i use a different url, everything works Is it possible to run a controller in

Using linked Resources in Custom REST Controller with Spring REST JPA

北战南征 提交于 2019-12-11 07:26:01
问题 I am developing a set of rest resources over a database and exposing the core CRUD functionality using Spring Data Rest to directly interact with the Repositories. In my simplified sample I have Users: @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) public long id; public String name; @OneToMany(mappedBy = "user") public Collection<Project> projects; } and users Own Projects: @Entity public class Project { @Id @GeneratedValue(strategy = GenerationType.AUTO)

Spring data rest validation for PUT and PATCH running after DB update

末鹿安然 提交于 2019-12-11 07:24:21
问题 I have a SDR project and I am successfully validating the user entity for POST request but as soon as I update an existing entity using either PATCH or PUT the DB is updated BEFORE the validation is executed (the validator is being executed and error is returned but the DB is being updated anyway). Do I need to setup a separate config for update ? Am I missing an extra step for that? Entity @Entity @JsonIgnoreProperties(ignoreUnknown = true) public class Member { @GeneratedValue(strategy =

Persistence Entity must not be null

柔情痞子 提交于 2019-12-11 06:36:51
问题 with following code I am getting error Persistence entity must not be null. what could be the mistake. public interface DistrictRepo extends PagingAndSortingRepository<District, Integer> { @Query( "select d.districtId, d.districtName from District d where d.districtId in (:districtIds) group by d.districtId" ) @RestResource(path="byList") List<Object[]> byList(@Param("districtIds") List<Integer> districtIds); } 回答1: If you are going to make a "search" method, use this approach: @Projection

POST MongoDB Extended JSON to a RepositoryRestController

梦想与她 提交于 2019-12-11 06:08:17
问题 I'm looking for a smart or elegant way to POST MongoDB Extended JSON to a REST controller of a web service developped with Spring Boot (1.5.1). My POJO contains well defined fields (mostly Strings), but also a Map<String, Object> data with is used to store generic data, meaning its specific structure is unknown at build time, and it will be fed by clients of the webservice. Please don't scold me, I know this is a poor design choice, but I was still asked to "make it happen" :) At some point,

Spring Data Rest - Bean validation is not applied to PUT method?

谁说胖子不能爱 提交于 2019-12-11 05:56:26
问题 I have a domain class defined as follows @Data @Entity public class City { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private long cityID; @NotBlank(message = "City name is a required field") private String cityName; } When I post to the endpoint http://localhost:8080/cities without a cityName I get a ConstraintViolationException but when I send a PUT request to the endpoint http://localhost:8080/cities/1 without a cityName I get the following exception

How can I change neo4j Id to UUID and get finder methods to work?

不打扰是莪最后的温柔 提交于 2019-12-11 05:51:21
问题 Neo4j needs an id field to work which is of type Long. This works well with Spring data neo4j. I would like to have another field of type UUID and have T findOne(T id) to work with my UUID not neo generated Ids. As I am using Spring Data Rest, I don't want to expose neo's id in the URL. http://localhost:8080/resource/{neoId} to http://localhost:8080/resource/{uuid} Any ideas if this is possible? UPDATED { name: "Root", resourceId: "00671e1a-4053-4a68-9c59-f870915e3257", _links: { self: { href

Upgrade to SpringBoot 2.1.2 throws IllegalArgumentException: Already found parameter binding with same name / parameter

无人久伴 提交于 2019-12-11 05:37:22
问题 I'm trying to upgrade a SpringBoot application from version 2.0.5-RELEASE to 2.1.2-RELEASE and I encounter a weird exception with a @Query annotation in a JpaRepository. This query was correct with release 2.0.5 but throws an IllegalArgumentException: Already found parameter binding with same index / parameter name but differing binding type! on startup with release 2.1.2. I wrote a sample project to reproduce this exception Sample project. Here is the sample @Query annotation: @RestResource