spring-data-rest

Modify @OneToMany entity in Spring Data Rest without its repository

假装没事ソ 提交于 2019-11-30 02:13:30
In my project I use object of type A which has OneToMany relation (orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER) to objects of type B . I need SpringDataRest (SDR) to store complete full A object with its B objects (children) using single one POST request. I tried several combinations in SDR, the only one which worked for me, was to create @RepositoryRestResource for object A and to create @RepositoryRestResource also for object B , but mark this ( B ) as exported=false (if I did not create repository out of object B at all, it would not work -> just A object would

How to add custom methods to Spring Data Rest JPA implementation and leverage HATEOS support?

一世执手 提交于 2019-11-30 02:08:30
I have a Spring Data Rest Repository controller that utilizes JPA for the query implementation, and I need to add some custom query methods that cannot be done using the standard queryByExample method that JPA supports. I have created an Impl class that has the necessary method, but I cannot get it to be recognized. I saw that I can utilize a standard Spring MVC Controller, but I want to have a unified API, and basically all I really want is to implement my own custom /search methods. Even with the custom controller, the problem is then that the HAL links and other related items are no longer

How to post a list to Spring Data Rest?

ぃ、小莉子 提交于 2019-11-30 01:17:38
问题 I followed this example, which allows to post a unique Person object. I want a REST service where I can post a collection of Person at once, e.g. a list/any collection named Team with numerous Person objects in just one call. I mean, my question is not exactly about the OneToMany relationship, where you send each person in a REST request. This topic is well answered. I want to send a collection of Person objects taking advantage of @RepositoryRestResource or another feature from Spring Data

How to get old entity value in @HandleBeforeSave event to determine if a property is changed or not?

回眸只為那壹抹淺笑 提交于 2019-11-30 00:11:41
I'm trying to get the old entity in a @HandleBeforeSave event. @Component @RepositoryEventHandler(Customer.class) public class CustomerEventHandler { private CustomerRepository customerRepository; @Autowired public CustomerEventHandler(CustomerRepository customerRepository) { this.customerRepository = customerRepository; } @HandleBeforeSave public void handleBeforeSave(Customer customer) { System.out.println("handleBeforeSave :: customer.id = " + customer.getId()); System.out.println("handleBeforeSave :: new customer.name = " + customer.getName()); Customer old = customerRepository.findOne

Repository access control in Spring Data Rest based off user princpal

≡放荡痞女 提交于 2019-11-29 23:19:12
I'm attempting to implement fine grain access control while still taking advantage of Spring data rest. I'm working on securing a CrudRepository so users can only modify or insert data that belongs to them. I'm making use of @PreAuthorize / @PostAuthorize and @PreFilter / @PostFilter to lock access down to the current principal. So far my repository looks like this. public interface MyRepository extends CrudRepository<MyObject, Integer> { @PreAuthorize("#entity.userId == principal.id") @Override <S extends MyObject> S save(S entity); @PreFilter("filterObject.userId === principal.id") @Override

Jackson @JsonFormat set date with one day less

血红的双手。 提交于 2019-11-29 21:47:02
I have been used Spring Date Rest with Spring Boot in my project. This project has a object and I have used the annotation @JsonFormat to format the date field that will be received from my Json. The format of field Date is "dd/MM/yyyy". When I send in my json the value "08/07/1980" the Jackson convert to the value "07/07/1980". The problem is that @JsonFormat set the date with one day less This is my source code @Temporal(TemporalType.DATE) @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy", locale = "pt-BR", timezone = "UTC") private Date birthDate; Thanks Hey guys use this

kotlin data class + bean validation jsr 303

谁都会走 提交于 2019-11-29 21:20:40
I'm trying to get Kotlin working with jsr 303 validation on a spring-data-rest project. Given the following data class declarartion : @Entity data class User( @Id @GeneratedValue(strategy = javax.persistence.GenerationType.AUTO) var id: Long? = null, @Size(min=5, max=15) val name: String ) The @Size annotation has no effect here, making me able to save a user with a name of 1 character. It works well when executing the very same example but in a Java class instead of Kotlin. This makes me think of a Kotlin problem. Thanks in advance for you help ! You need to use Annotation use-site targets

How do I avoid n+1 queries with Spring Data Rest?

你。 提交于 2019-11-29 19:39:14
Question. How do I avoid n+1 queries with Spring Data REST? Background. When querying Spring Data REST for a list of resources, each of the resulting top-level resources has links to the associated resources, as opposed to having the associated resources embedded directly in the top-level resources. For example, if I query for a list of data centers, the associated regions appear as links, like this: { "links" : [ { "rel" : "self", "href" : "http://localhost:2112/api/datacenters/1" }, { "rel" : "datacenters.DataCenter.region", "href" : "http://localhost:2112/api/datacenters/1/region" } ],

How do I apply a projection to a Spring Data REST query method resource?

时光毁灭记忆、已成空白 提交于 2019-11-29 18:37:06
问题 I'm using Spring Data REST 2.1.4.RELEASE. I created an entity Booking , its REST repository (extending CrudRepository ) named BookingRepository and a projection BookingDetails (annotated with @Projection(name="details", types = Booking.class) ) for returning some of its linked entities exploded, such as Resource , Activity , Applicant etc. The client gets all bookings with .../rest/bookings and the JSON response includes links for the linked entities. If it adds ?projection=details then the

Creating Resource with references using spring data rest

泪湿孤枕 提交于 2019-11-29 17:45:59
I am using spring data rest, I have following entities exposed via spring data rest DonationRequest @Data @Entity @Table(name="donation_request",schema="public") public class DonationRequest { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="donation_request_id") Integer donationRequestId; @Column(name="expiry_datetime") Date expiryDatetime; @Column(name="blood_group") String bloodGroup; @Column(name="no_of_bottles") String noOfBottles; @OneToOne @JoinColumn(name="hospital_id") Hospital hospital; @OneToOne @JoinColumn(name="user_data_id") UserData requester; @Column(name=