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

Uninitialized HIbernateProxy cannot be deleted by repository

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 2.1.10 (Lovelace SR10)
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      I have such base entity class with private version property:

      public abstract class AbstractEntity {
       ... 
        @Version 
        @Column(nullable = false) 
        private Long getVersion() { return version; } 
        
        private void setVersion(Long version) { this.version = version; }
      }

      When I try to delete entity (which is actually uninitialized hibernate proxy) by entity repository, the deletion does not occur.

      Document document = documentLine.getDocument();
      Assert.assertFalse("Document must not be initialized.", Hibernate.isInitialized(document));
      Assert.assertThat(document, IsInstanceOf.instanceOf(HibernateProxy.class));
      documentRepository.delete(document);

      Method

      java org.springframework.data.jpa.repository.support.SimpleJpaRepository.delete(T entity)

      detects that entity is new entity.

      But if I try to delete implementation of proxy then the deletion occurs as expected.

      In attached project you could find two test cases to reproduce issue.

      In the first test case, an attempt is made to delete a proxy. (fail)
      In the second test case, an attempt is made to delete a unproxy entity. (success)

      Issue reproduces in versions of spring.data.releasetrain.version Lovelace-SR10 and Lovelace-SR9.

      Before version Lovelace-SR9 both test cases complete successfully.

      Libraries versions:

       

      {{<properties>
      <version.com.h2database>1.3.176</version.com.h2database>
      <version.junit>4.12</version.junit>
      <version.org.hibernate>5.4.4.Final</version.org.hibernate>
      <spring.version>5.1.9.RELEASE</spring.version>
      <spring.boot.version>2.1.6.RELEASE</spring.boot.version>
      <spring.data.releasetrain.version>Lovelace-SR10</spring.data.releasetrain.version>
      <hamcrest.version>1.3</hamcrest.version>
      <validation.api.version>2.0.1.Final</validation.api.version>
      <hibernate.validator.version>6.0.17.Final</hibernate.validator.version>
      </properties>}}

      // code placeholder
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              schauder Jens Schauder
              Reporter:
              toughpheeckouse toughpheeckouse
              Last updater:
              toughpheeckouse
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: