Giter Site home page Giter Site logo

Comments (3)

mp911de avatar mp911de commented on June 21, 2024

Spring Data JPA uses a @PrePersist/@PreUpdate lifecycle hook via AuditingEntityListener. While I wasn't immediately able to find any JPA rules that would prevent updating the identifier in a lifecycle method, I can well imagine why updating an identifier isn't a great idea.

Spring Data JPA has upgraded with 3.2.x to Hibernate 6.4 whereas Spring Data 3.1.x used Hibernate 6.2.

Embeddables aren't necessarily identifiers and the check that raises the exception relies on the implementation of equals/hashCode. The exception comes from within Hibernate so I suggest that you create a reproducer using purely Hibernate API for @PrePersist updating an identifier (id-class) and report it against Hibernate.

from spring-data-jpa.

imuhdork avatar imuhdork commented on June 21, 2024

Putting this here in case I get nowhere with hibernate. I was able to reproduce the issue removing auditing completely and just using @PrePersist. The @PrePersist method and tests work fine in 6.2.21.Final and the @IdClass test case fails in 6.2.22.Final.

It appears that between 6.2.21.Final and 6.2.22.Final the composite key @Id values set in a @PrePersist method on an @Entity get overwritten by hibernate. In 6.2.21.Final the tests pass, in 6.2.21.Final the @IdClass test fails because the @Id values are null even though the are set in the @PrePersist method. It is only when we get to 6.3.1.Final when the HibernateException is thrown.

Going even further, not only are the @Id properties overwritten but it appears that @PrePersist gets called twice in 6.2.22.Final and beyond in the @IdClass test case and only once in the @Embeddable test case.

from spring-data-jpa.

imuhdork avatar imuhdork commented on June 21, 2024

Created hibernate defect and test case template compliant repo.

from spring-data-jpa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.