spring-projects / spring-projects/spring-data-rest

PATCH REST call and default some entity columns [DATAREST-1534]

Open
#1,890 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

snehi23 opened DATAREST-1534 and commented

I build my REST api around Oracle entities using spring data rest. 
With the use case of updating only one entity field, I am using PATCH url.
This entity has some columns which needed to be defaulted at every update (or patch to be specific) call. For example :

  @UpdateTimestamp

  @Column(name = "LAST_UPDATED_DATE")

  private Date lastUpdatedDate;

 
@Column(name = "LAST_UPDATED_BY")

  private String lastUpdatedBy = "XXXX";

But setting up defaults is not working for field lastUpdatedBy

If I use PUT url and provide all column values except those set to default, it is updating as expected.
But I was wondering why there is no support for PATCH like that.

Version :

<parent>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-parent</artifactId>

    <version>2.3.0.RELEASE</version>

    <relativePath />

</parent>

  spring-boot-starter-data-rest : 2.3.0.RELEASE

 
Entity :

@Entity

@Table(name = "XXXX", schema = "XX")

@Data

@NoArgsConstructor

public class OracleSupplier

{   @Id   @NonNull   @Column(name = "COUPA_SUPPLIER_ID")   private Long coupaSupplierId;     @Column(name = "COUPA_HTTP_STATUS")   private String coupaHTTPStatus;     @Column(name = "ERROR_DESCRIPTION")   private String errorDescription;     @Column(name = "STATUS")   private String status;     @NonNull   @Column(name = "SIM_ID")   private Long simId;     @Column(name = "COUPA_SUPP_NUM")   private String coupaSupplierNum;     @Column(name = "COUPA_SUPP_NAME")   private String coupaSupplierName;     @Column(name = "ATTRIBUTE1")   private String attribute1;     @Column(name = "ATTRIBUTE2")   private String attribute2;     @Column(name = "ATTRIBUTE3")   private String attribute3;     @Column(name = "CREATED_BY")   private String createdBy;     @Column(name = "CREATION_DATE")   private Date creationDate;     @UpdateTimestamp   @Column(name = "LAST_UPDATED_DATE")   private Date lastUpdatedDate;     @Column(name = "LAST_UPDATED_BY")   private String lastUpdatedBy = "XYZ";     @Column(name = "ADDRESS_LINE1")   private String addressLine1;     @Column(name = "ADDRESS_LINE2")   private String addressLine2;     @Column(name = "CITY")   private String city;     @Column(name = "STATE")   private String state;     @Column(name = "COUNTRY")   private String country;     @Column(name = "POSTAL_CODE")   private String postalCode;     @Column(name = "REMIT_TO_CODE")   private String remitToCode;     @Column(name = "ATTRIBUTE4")   private String attribute4; }

Repository :

@RepositoryRestResource(collectionResourceRel = "oracleSupplier", path = "oracle-supplier")

public interface OracleSupplierStagingRepository

    extends PagingAndSortingRepository<OracleSupplier, Long>

{     List<OracleSupplier> findByCoupaSupplierId(       @Param("COUPA_SUPPLIER_ID") Long coupaSupplierId);     List<OracleSupplier> findByStatus(@Param("STATUS") String status);     List<OracleSupplier> findByCoupaSupplierIdAndStatus(       @Param("COUPA_SUPPLIER_ID") Long coupaSupplierId, @Param("STATUS") String status); }

 


No further details from DATAREST-1534

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.