Giter Site home page Giter Site logo

Comments (4)

quaff avatar quaff commented on September 27, 2024

I don't think entityManager.persist(entity) will know that field is generated by database.

Even when I tried fetching the object after the save the object do not contain the value form the database.

You should call entityManager.detach(entity) or entityManager.refresh(entity) first.

from spring-data-jpa.

assemble-code avatar assemble-code commented on September 27, 2024
  1. I tried entityManager.detach(savedEntity) and it worked,

  2. but one thing i am not able to wrap head around is that even if the save is transactional and entity is committed then the entity in entityManager is detached , then findBy.. should not return older data as it shows selecte query being fired so it should get the new value as per my current understanding .

  3. if the save or any method that can modify the value of db is called, shouldn't data be fetched from the database rather than using the persistent cache, As Save might have caused some fields to modified as result of db trigger or auto generated column, etc.

Sorry if questions are naive @quaff

from spring-data-jpa.

quaff avatar quaff commented on September 27, 2024
  1. I tried entityManager.detach(savedEntity) and it worked,
  2. but one thing i am not able to wrap head around is that even if the save is transactional and entity is committed then the entity in entityManager is detached , then findBy.. should not return older data as it shows selecte query being fired so it should get the new value as per my current understanding .
  3. if the save or any method that can modify the value of db is called, shouldn't data be fetched from the database rather than using the persistent cache, As Save might have caused some fields to modified as result of db trigger or auto generated column, etc.

Sorry if questions are naive @quaff

If your findBy... and save are in the same transaction, it will try to load entity from persistent context not database, if they are not in the same transaction but second level cache is enabled, it will try to load entity from cache not database.

from spring-data-jpa.

mp911de avatar mp911de commented on September 27, 2024

Closing this one as the save method behaves as designed along with JPA attached entity semantics. Any specifics that concern database-generated activity, flushing are out of our control as we use EntityManager.persist(…) in the regular case.

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.