spring-data-rest

spring data rest vs spring data jpa

天涯浪子 提交于 2019-12-03 07:22:34
问题 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 REST can give me which I wont find in simple Spring-Data-JPA? For example if tomorrow, I decide to implement a cache b/w my business and Database module, in which case would I have to write lesser code? Which would be easily configurable? Which

Spring Data Rest PUT v.s PATCH LinkableResources

人盡茶涼 提交于 2019-12-03 06:59:29
I'm using Spring Data REST to expose my Entity's and their relationships. I have a OneToOne relationship between two Entity's and I'm trying to update/change the relationship with PUT and PATCH. I noticed that Spring Data REST will only allow you to update linked resources - JPA mapped Entity's (OneToMany, ManyToOne, etc) which are also AggregateRoots (has a Repository) - via a PATCH and are ignored with a PUT . This can be seen in the LinkedAssociationSkippingAssociationHandler class: if (associationLinks.isLinkableAssociation(association)) { return; } Why is this? What is the reasoning

Spring Data Rest Validation Confusion

不羁岁月 提交于 2019-12-03 06:08:17
问题 Looking for some help with Spring data rest validation regarding proper handling of validation errors: I'm so confused with the docs regarding spring-data-rest validation here: http://docs.spring.io/spring-data/rest/docs/current/reference/html/#validation I am trying to properly deal with validation for a POST call that tries to save a new Company entity I got this entity: @Entity public class Company implements Serializable { @Id @GeneratedValue private Long id; @NotNull private String name;

using validators in spring-data-rest returns http 500 instead of 400

夙愿已清 提交于 2019-12-03 06:00:38
I'm trying to get the validation in spring-data-rest to work. From the documentation you only need to make a validator available, and I've got that to work, but when a validation constraint is successfully caught/processed I get a 500 error page with the stack trace. In the config class, RepositoryRestMvcConfiguration it has a validationExceptionHandler which looks like it should get such validation errors to return as 400 rather than 500. It is also a lazy loaded bean. Do I have an incorrect setup? or is there another way to get spring-data-rest to return 400 instead of 500? I'm using spring

Exclude some fields of Spring-data-rest resource

时光毁灭记忆、已成空白 提交于 2019-12-03 05:51:40
I'm trying to use Spring-data-rest with spring-data-mongodb to expose read-only resources. The problem I met, is that I want to have different views of my documents. Let's say I have some private information in a document, I don't want to expose them publicly. So I tried several ways. I read this post https://spring.io/blog/2014/12/02/latest-jackson-integration-improvements-in-spring describing how to use JsonView in order to select the fields we want to expose. I've tried like this : @RepositoryRestResource(collectionResourceRel = "recommandation", path = "recommandations") interface

QueryDsl web query on the key of a Map field

北城以北 提交于 2019-12-03 05:18:37
Overview Given Spring Data JPA, Spring Data Rest, QueryDsl a Meetup entity with a Map<String,String> properties field persisted in a MEETUP_PROPERTY table as an @ElementCollection a MeetupRepository that extends QueryDslPredicateExecutor<Meetup> I'd expect A web query of GET /api/meetup?properties[aKey]=aValue to return only Meetups with a property entry that has the specified key and value: aKey=aValue. However, that's not working for me. What am I missing? Tried Simple Fields Simple fields work, like name and description: GET /api/meetup?name=whatever Collection fields work, like

Accepting a Spring Data REST URI in custom controller

元气小坏坏 提交于 2019-12-03 04:52:07
I have a Spring Data Rest webmvc application that I'd like to add some custom functionality to for batch operations. I've created a controller, and blended it into the uri namespace, but I'd like for it to be able to accept URI's like the custom /search queries do, rather than simply an ID. I have tried registering a custom <String, Long> converter (my entity has a Long ID type, but that seems to get ignored. Is there any way to configure my controller such that it adopts that behavior from the auto-implemented SDR controllers? Even if there is some sort of method I can call that will auto

How to map Page<ObjectEntity> to Page<ObjectDTO> in spring-data-rest

放肆的年华 提交于 2019-12-03 04:06:59
问题 When I hit the database with PagingAndSortingRepository.findAll(Pageable) I get Page<ObjectEntity> . However, I want to expose DTO's to the client and not entities. I can create DTO just by injecting entity into it's constructor, but how do I map the entities in Page object to DTO's? According to spring documentation, Page provides read-only operations. Also, Page.map is not possibility, as we don't have support for java 8. How to create the new Page with mapped objects manually? 回答1: You can

Spring Data Rest exception handling - Return generic error response

☆樱花仙子☆ 提交于 2019-12-03 00:34:49
I want to know how can I handle internal server error type exceptions in Spring Data Rest such as JPA exceptions etc. due to a malformed request or a database crash. I did some research found that the better way to do this is by using @ControllerAdvice but couldn't find any working example of it. I looked at both these questions but they are still unanswered. How can I handle exceptions with Spring Data Rest and the PagingAndSortingRepository? global exception handling for rest exposed spring-data Can someone help me with a working example of how to use @ControllerAdvice and write a custom

Filling entity links in custom @RepositoryRestController methods

天涯浪子 提交于 2019-12-02 22:54:09
I am using Spring-data-rest to provide read APIs over some JPA entities. For writes I need to issue Command objects rather than directly write to the DB, so I added a custom controller using @RepositoryRestController and various command handling methods: @RequestMapping(method = RequestMethod.POST) public @ResponseBody MyEntity post(@RequestBody MyEntity entity) { String createdId = commands.sendAndWait(new MyCreateCommand(entity)); return repo.findOne(createdId); } I would like the output to be enriched just like any other response by the spring-data-rest controller, in particular I want it