spring-data-rest

How to have PersistentEntityResourceAssembler injected into request methods of custom @RepositoryRestController in a @WebMvcTest unit test

你离开我真会死。 提交于 2019-12-01 22:16:22
Overview How can I have a PersistentEntityResourceAssembler properly injected into my custom REST controller's request methods during a @WebMvcTest unit test? First SO question. Apologies in advance, probably just missing something stupid. Sample code available on GitHub . Oliver Gierke, where you at? :P Details I have a custom REST controller annotated with @RepositoryRestController . Some of its request methods have a PersistentEntityResourceAssembler injected as an argument so I can return HAL resources. @RepositoryRestController @RestController @RequestMapping(produces = MediaTypes.HAL

Spring Data Rest: How to search by another object's key?

妖精的绣舞 提交于 2019-12-01 21:04:43
In Spring-Data-Rest an object's ID is the URI returned with the object. For example, if I have a User, it might have a URI like: http://example.com/users/1 In an authentic REST api, this URI is the id of the object, you are not supposed to use just '1' as the id. Give that, how do I search for all Orders that belong to that User? http://example.com/orders/search/findByUser?user={{XXX}} Specifically, what do I use for {{XXX}}? I know I could do the opposite search: http://example.com/users/1/orders But in my case I need to search for matching jobs so I can add additional parameters which are

Spring Data Rest - can not update (PATCH) a list of child entities that have a reference to another entity

时光毁灭记忆、已成空白 提交于 2019-12-01 20:04:55
I have three entities: Parent, its Child and some Reference: Parent @Entity @Table(name = "parents") public class Parent extends LongId { @NonNull @Column(nullable = false) private String name = "Undefine"; @NonNull @OneToMany(cascade = MERGE) private List<Child> children = new ArrayList<>(); } Child @Entity @Table(name = "children") public class Child extends LongId { @NonNull @Column(nullable = false) private String name; @NonNull @ManyToOne(optional = false) private Reference reference; } Reference @Entity @Table(name = "references") public class Reference extends LongId { @NotEmpty @Column

Spring Data Rest - can not update (PATCH) a list of child entities that have a reference to another entity

走远了吗. 提交于 2019-12-01 18:57:21
问题 I have three entities: Parent, its Child and some Reference: Parent @Entity @Table(name = "parents") public class Parent extends LongId { @NonNull @Column(nullable = false) private String name = "Undefine"; @NonNull @OneToMany(cascade = MERGE) private List<Child> children = new ArrayList<>(); } Child @Entity @Table(name = "children") public class Child extends LongId { @NonNull @Column(nullable = false) private String name; @NonNull @ManyToOne(optional = false) private Reference reference; }

Select one column using Spring Data JPA

给你一囗甜甜゛ 提交于 2019-12-01 15:18:13
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 Restful URL. @RepositoryRestResource(collectionResourceRel = "users", path = "users") public interface UsersRepository extends CrudRepository<Users, Integer> { @Query("SELECT u.userName FROM Users u") public List<String> getUserName(); } Then if I access the Restful URL like ../users/search/getUserName , I get the error: {"cause":null,"message":

Is it possible to use spring-data-rest-webmvc without an actual Repository?

不羁的心 提交于 2019-12-01 13:57:51
The question may sound funny but I think this should be possible. What I want is to use a repository that is purely custom but is exposed just like a Repository. This service would have methods to get, save, delete and list objects where the data could be from any arbitrary source. Looking through the code, I think it should be possible since methods are accessed using CrudMethods and RepositoryInvoker . I belief this requires an implementation of RepositoryFactoryInformation that will be discovered by Repositories . I started experimenting a bit and it looks like a full-blown spring-data-noop

Unable to retrieve Spring HATEOAS embedded resource object in case of @ManytoMany relationship and lookup table with extra column

不打扰是莪最后的温柔 提交于 2019-12-01 10:31:11
I am unable to retrieve embedded .I am using Spring boot ,spring data rest and spring JPA. I have 3 tables in data base user competency user_competency (join/composite table with extra column) User @Entity @Table(name = "\"user\"", schema = "public") @JsonIdentityInfo( generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "userId") public class User implements java.io.Serializable { private Long userId; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "user_id", unique = true, nullable = false) public Long getUserId() { return this.userId; } public void

@RepositoryEventHandler events stop with @RepositoryRestController

柔情痞子 提交于 2019-12-01 09:56:21
When I create a @RepositoryRestController for an entity, the associated @RepositoryEventHandler methods are not triggered in Spring Data REST via Spring Boot 1.4.0.M3 (also Spring Boot 1.3.5) -- is this a bug, or as designed ? I have an Account entity with an @RepositoryEventHandler : @Slf4j @Component @RepositoryEventHandler(Account.class) public class AccountEventBridge { @HandleBeforeCreate public void handleBeforeCreate(Account account){ log.info("Before create " + account); } @HandleAfterCreate public void handleAfterCreate(Account account){ log.info("Created " + account); } } which

how to configure spring-data-rest search method path with @PathVariable

别等时光非礼了梦想. 提交于 2019-12-01 09:45:29
问题 I want to customize my spring-data-rest search method path by passing parameter as a path variable like follows http://localhost:8080/orders/search/customers/{customerId} findByCustomer(@PathVariable("customerId") Integer customer); The search resource listh the links as follows http://localhost:8080/orders/search/customers/%7BcustomerId%7D How to expose search url with path params? 回答1: You can use custom handler similar to this: @RepositoryRestController public class OrderController {

@RepositoryEventHandler events stop with @RepositoryRestController

喜夏-厌秋 提交于 2019-12-01 08:27:06
问题 When I create a @RepositoryRestController for an entity, the associated @RepositoryEventHandler methods are not triggered in Spring Data REST via Spring Boot 1.4.0.M3 (also Spring Boot 1.3.5) -- is this a bug, or as designed ? I have an Account entity with an @RepositoryEventHandler : @Slf4j @Component @RepositoryEventHandler(Account.class) public class AccountEventBridge { @HandleBeforeCreate public void handleBeforeCreate(Account account){ log.info("Before create " + account); }