spring-data-rest

Spring Data REST - difference between @PrePersist and @HandleBeforeCreate?

筅森魡賤 提交于 2019-12-05 07:27:10
I use Spring Data Rest over JPA mappings. JPA provides @PrePersist annotation for methods to be called before the persistence of en entity in the DB. Spring Data Rest provides @HandleBeforeCreate annotation for method to be called when catching an entity creation event. This seems rather equivalent to me. When should I use one and when should I use the other ? @HandleBeforeCreate is only called when a REST request comes in but @PrePersist is called during the entities lifecycles. So, if your call path is not through the REST (for instance by calling the entity manager directly or due to the

Changing the JSON format for spring-data-rest

柔情痞子 提交于 2019-12-05 07:20:53
Currently spring-data-rest is returning JSON in HAL format in a spring-boot project of mine. I am using an ember.js frontend and want to use jsonapi ( http://jsonapi.org/ ) specification. How might I register a new JSON formatting strategy given I will need to write the formatter myself as one does not exists yet? This is how you can customize the HATEOAS that Spring Data REST produces: https://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.customizing-json-output If you need to completely replace the JSON representation with your own, then you can write and

Spring Data Rest : Foreign key is update with null after post call in one to many relationship

前提是你 提交于 2019-12-05 06:37:02
I am using spring-data-rest . update and daily_update are 2 table which is having one to many relationship. Running this application with spring boot. When i am adding data using post request, entries being added into both table without any error but in child table (daily_update) column "update_id" (foreign key to update table) is coming null . I am using Lombok for setter and getter. Can you please help me with this? UpdateEntity class : @Data @Entity @Table(name = "update") public class UpdateEntity { @Id @Column(name = "id") @GeneratedValue(generator = "UUID") @GenericGenerator(name = "UUID

Does Spring Data REST support JPA @Version?

冷暖自知 提交于 2019-12-05 04:02:40
Can I use JPA @Version with Spring Data REST? In Spring Data REST 1.1.0.M1 I can configure the repo exporter to expose the entity ID, which as it happens also exposes @Version -annotated fields. So I thought that if I tried to PUT an entity with some old version number, I'd get the OptimisticLockException . But that doesn't occur. Instead the PUT succeeds (including data updates), except that the version number is always strictly incremented instead of being whatever old version I set it to. I read here that I'm not supposed to set the version number myself, since the behavior is undefined.

Spring Data Rest - _links

邮差的信 提交于 2019-12-05 02:53:05
问题 Edit 14/08/14 13:29 My next conclusion is that the hal+json format produced from my @RepositoryRestResource CrudRepository is incorrect. The tutorial (http://spring.io/guides/gs/accessing-data-rest/) shows the output of a hypermedia Rest JPA entity as: (please note there is no "rel" element, and "links" is not an array) { "_links" : { "people" : { "href" : "http://localhost:8080/people{?page,size,sort}" } } } However, the reference docs (http://docs.spring.io/spring-data/rest/docs/1.1.x

Spring Data Rest Ambiguous Association Exception

天大地大妈咪最大 提交于 2019-12-05 02:04:46
The newly added LinkCollectingAssociationHandler is throwing a MappingException due to an ambiguous association in my domain class. The links array looks like this: [<http://localhost:8080/rooms/2/roomGroups>;rel="roomGroups", <http://localhost:8080/rooms/2/userGroup>;rel="userGroup", <http://localhost:8080/rooms/2/room>;rel="room", <http://localhost:8080/rooms/2/originatingConferences>;rel="originatingConferences", <http://localhost:8080/rooms/2/user>;rel="user"] And it is trying to add another 'room' relation when it throws the exception. The issue is that it seems to be adding links to

Spring JPA REST One to Many

左心房为你撑大大i 提交于 2019-12-05 02:01:57
I wanted to extend the example Accessing JPA Data with REST by adding an address list to the Person entity. So, I added a list addresses with @OneToMany annotation: @Entity public class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; private String firstName; private String lastName; @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) private List<Address> addresses = new ArrayList<>(); // get and set methods... } The Address class is a very simple one: @Entity public class Address { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id;

How to disable paging for JpaRepository in spring-data-rest

寵の児 提交于 2019-12-05 01:45:58
I'm using spring-data-rest with JpaRepository to create the Rest-Endpoints. By default, paging is enabled for all JpaRepository , what is a good thing. But I have a legacy application that we port to our new stack that does not support paging. I would like to disable paging depending on an URL-Parameter to still be able to use paging in new application code. I tried various approaches to expose the resources with and without paging: Use CrudRepository : Results in only having an unpaged endpoint and the method flush is missing. Override the List<T> findAll() method in my repository interface

Spring Data Rest - Add link to search endpoint

落花浮王杯 提交于 2019-12-05 01:24:19
问题 In our Spring-Data-Rest Project we have a custom (fuzzy) search on a /buergers/search/findBuergerFuzzy?searchString="..." endpoint. Is it possible to add a link for it on the /buergers/search endpoint (Without overriding the automatically exposed Repository findBy Methods)? The Controller exposing the search: @BasePathAwareController @RequestMapping("/buergers/search/") public class BuergerSearchController { @Autowired QueryService service; @RequestMapping(value = "/findBuergerFuzzy", method

How to exclude a @Repository from component scan when using Spring Data Rest

不羁的心 提交于 2019-12-05 00:10:03
问题 in a spring boot project I have problems to exclude some repositories from the component scan. I have a library that contains some entities and some repositories (JpaRepositories). For some reason I implemented a small Spring Boot Data Rest application that shall be used to give testers a quick access to the entities. Therefore I implemented a repository that extends the PagingAndSortingRepository and is annotated with @RepositoryRestResource. When the application starts all repository will