Uploaded image for project: 'Spring Data JPA'
  1. Spring Data JPA
  2. DATAJPA-1565

SimpleJpaRepository.delete does not respect JPA `@Access` rules

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1.9 (Lovelace SR9)
    • Fix Version/s: None
    • Component/s: None

      Description

      With the changes of DATAJPA-1535 (https://github.com/spring-projects/spring-data-jpa/commit/c1d99ae77ed5b69b6955f075b777538ae1e3812d) a bug was introduced.

      According to JPA rules the position of the annotation defines whether field or property access is used. It can be overridden with the @Access annotation. It seems that org.springframework.data.jpa.repository.support.JpaEntityInformation does not respect that since entityInformation.getId(entity) uses DirectFieldAccessFallbackBeanWrapper which tries the property access first. This can lead to problems if the getter returns a different type than the type of the actual field.

      @Entity
      public class ExampleEntity {
      
          @Id
          @Column(columnDefinition = "uuid")
          @GeneratedValue(generator = "uuid2")
          @GenericGenerator(name = "uuid2", strategy = "uuid2")
          private UUID clientId;
      
          public UUID getId() {
              return clientId;
          }
      
          public void setClientId(UUID clientId) {
              this.clientId = clientId;
          }
      
          public String getClientId() {
              return clientId == null ? null : clientId.toString();
          }
      }
      
      

      Fails with (see attached sample)

      org.springframework.dao.InvalidDataAccessApiUsageException: Provided id of the wrong type for class com.example.datajpaidaccessbug.db.ExampleEntity. Expected: class java.util.UUID, got class java.lang.String; nested exception is java.lang.IllegalArgumentException: Provided id of the wrong type for class com.example.datajpaidaccessbug.db.ExampleEntity. Expected: class java.util.UUID, got class java.lang.String
       at com.example.datajpaidaccessbug.DatajpaIdAccessBugTests.deletionFails(DatajpaIdAccessBugTests.java:22)
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              schauder Jens Schauder
              Reporter:
              leonard84 Leonard Brünings
              Last updater:
              Mark Paluch
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: