spring-data-rest

Spring Data REST: custom methods validation

家住魔仙堡 提交于 2019-12-06 13:44:55
问题 I'm trying to use Spring Data REST repositories annotated with @RepositoryRestResource annotation together with custom methods implementation. There are 2 cases: 1) I have REST repository annotated with @RepositoryRestResource which is mapped to /users endpoint. Also, I have @RestController which is mapped to the same endpoint. That results in methods (which should be exposed) in @RepositoryRestResource to not be visible and getting 405 result on them. However method validation with @Valid

Extend RepositoryRestExceptionHandler

Deadly 提交于 2019-12-06 12:55:40
问题 I want to extend RepositoryRestExceptionHandler to handle errors in my RestController. I have Validators and working great when using RestRepository but when i use RestController they are not so i did manual Validation like below Errors errors = new BeanPropertyBindingResult(NumberRange, "range"); NumberRangeValidator.validate(NumberRange, errors); if(errors.hasErrors()) { throw new RepositoryConstraintViolationException(errors); } this is resulting in error 500 , what i want to have as

Javers - What are advantages of using Javers instead of Envers?

淺唱寂寞╮ 提交于 2019-12-06 11:21:45
I am developing a RESTful API using Spring Data REST. Now for auditing, Spring does have the option to auditing meta data like created_date and modified_date but they don't provide entity versioning. Currently there are two popular libraries for entity version which are Envers and Javers. I have looked over for a comparison of both but there arent any articles on this matter. So what are the benefits and drawbacks of using Javers over Envers? There are two big difference between JaVers and Envers: Envers is the Hibernate plugin. It has good integration with Hibernate but you can use it only

How to use spring.data.rest.enable-enum-translation in Spring Data REST

坚强是说给别人听的谎言 提交于 2019-12-06 10:21:59
问题 I'm using Spring Boot 1.5.3, Spring Data REST, HATEOAS, Hibernate. In my model sometimes I'm using enum like: public enum Roles { ROLE_ADMIN, ROLE_USER, ROLE_MANAGER, ROLE_TECH } According to Spring Boot documentation, there is a property that seems useful: # DATA REST (RepositoryRestProperties) spring.data.rest.enable-enum-translation=true I didn't find documentation about how to use that. I found old references where seems I should add something like: roles.role_admin=Amministratore in my

How to write paginated controller that expose resource or list of resource in spring-data-hatoas

若如初见. 提交于 2019-12-06 09:55:12
Using spring-data, I want to write two method for my Person entity. Person.java: public class Person { @Id String id; String name; Integer age; // getters/setters omitted for clarity } I have written also a PersonResouce : public class PersonResource extends Resource<Person> { public PersonResource(Person content, Link... links) { super(content, links); } } I have also added a PersonResourceAssembler : public class PersonResourceAssembler extends ResourceAssemblerSupport<Person, PersonResource> { public PersonResourceAssembler() { super(PersonController.class, PersonResource.class); } public

Spring-data-rest and Spring-jpa [closed]

霸气de小男生 提交于 2019-12-06 09:47:38
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . data-rest and jpa. I have created one entity with composite keys using @EmbeddedId and repository extends CrudRepository with findById query param when I enter the URL [a link] (http://localhost:8080/data/person

Spring data rest validation + exception mapper: confusing

为君一笑 提交于 2019-12-06 08:10:53
I am using Spring Data Rest and all is going well. I want to apply validation (JSR 303) on my entities. The spring docs say I can intercept application events in a few ways (none of which I can get to work, and right now spring.io seems to be down). However, I did get it working by putting @Validated on my respository: @Validated @RepositoryRestResource(collectionResourceRel = "workers", path = "workers") public interface WorkerRepository extends PagingAndSortingRepository<Worker, Long> { } And it will throw an exception. Problem is it's a spring exception and not even the root one, and I need

Spring JPA Projection including links

ⅰ亾dé卋堺 提交于 2019-12-06 08:05:10
问题 Given a simple model of Event that has a Set of Booking objects: Event: @Entity public class Event { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long eventId; private Date start; private Date end; private String title; @OneToMany(mappedBy="event") private Set<Booking> Bookings; protected Event() { // for JPA } // Getters and setters omitted for brevity } Booking: @Entity public class Booking { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long bookingId; private

How to disallow PUT while allowing POST and PATCH in Spring Data REST?

北城余情 提交于 2019-12-06 05:59:03
问题 Is it possible to completely disallow PUT for a repository in Spring Data REST while POST on the collection and PATCH on the item remain possible? The rationale behind this is that a PUT typically allows for replace semantics, but in our case the resource can only be created via POST on the collection, partially updated via PATCH on the item (using specific UI dialogs... each of which only supports a particular partial update), or deleted via DELETE on the item. 回答1: If you have Spring

E11000 duplicate key error when doing PUT for modifiable resource with Spring Data Rest

不羁的心 提交于 2019-12-06 05:53:41
Update: According to this question, the author of Spring data rest say, the @Version properties will become ETags in response header. And there are two options for update: Just PUT without an If-Match header -- enforces overriding whatever is present on the server as the aggregate gets loaded, incoming data mapped onto it and it written back. You still get optimistic locking applied if another client changed the aggregate in the meantime (although an admittedly very short window). If that's the case you'll see a 409 Conflict. I am currently using this way for PUT, and a 409 conflict is what I