Spring Boot EntityManager : Understanding Persistence Context and Key Methods

  Рет қаралды 1,892

TheCodeAlchemist

TheCodeAlchemist

Күн бұрын

Пікірлер: 12
@عبدالرحمنخالد-ش4ت6ي
@عبدالرحمنخالد-ش4ت6ي 21 күн бұрын
Excellent
@ankitatripathi1548
@ankitatripathi1548 Ай бұрын
So when we persist the entity and then if we change the data of entity it will sync, then whats the difference between merge and persist as i see both are doing the same
@pradeepsingh-kr2hv
@pradeepsingh-kr2hv Ай бұрын
Subscribed, thanks for good explanation
@the_codealchemist
@the_codealchemist Ай бұрын
Thanks!
@sree6484
@sree6484 6 ай бұрын
Really liked your video, you earned a subscriber
@the_codealchemist
@the_codealchemist 6 ай бұрын
Thanks!
@sree6484
@sree6484 6 ай бұрын
When i detach an object from context, changes made to that object wont be tracked lets assume i did some changes to it, what if i want to set the object properties back to the changes tracked by the hibernate? I can't use refresh here because assuming that record in database is also changed and if i do refresh object data in context gets refreshed with data from db and i don't want that, what to do in this scenario?
@the_codealchemist
@the_codealchemist 6 ай бұрын
Correct, refresh means you want to refresh it from the DB. In this case, you can use merge to reattach the object.
@sree6484
@sree6484 6 ай бұрын
@@the_codealchemist if I use merge, untracked changes gets merged with the context but I don't want those untracked changes I want to set my object properties back to same the properties which were last tracked by the hibernate. I'll also go through your practical video to get more understanding on this.
@the_codealchemist
@the_codealchemist 6 ай бұрын
I think I got your point. You basically want to revert the object to it's last tracked state without merging untracked changes and refreshing from the DB. AFAIK, Hibernate doesn't handle it automatically so you'll have to do it manually e.g. saving the object state without detaching the entity..maybe a clone or deep copy and then using this copy to reset the state when you want to track again.
@universal4334
@universal4334 5 ай бұрын
Entity manager factory is created at boot up time. So, when is this persistence context created ? I mean, how can it track/cache all the data that is in db. As for my understanding, it maintains the latest state, and when we do any operation, it checks with the maintained state of an object. Let's say i have a million unique objects, will persistence context maintains all of them, or how it is Will there be multiple instances of persistence context ? When it is created and destroyed 😢
@the_codealchemist
@the_codealchemist 5 ай бұрын
Hi, I think you're bit confused with EntityManager and persistence context..persistence context is a short-lived, transaction-scoped cache that manages the state of entities within a specific transaction or unit of work, rather than caching the entire database like any other caching solution. So it's different from any cache that you might know like Redis, Caffiene. Second, it's created automatically when you create a new instance of EntityManager(similar to Hibernate session) which is not created at startup..that is EntityManagerFactory which is created at server startup(similar to Hiernate's SessionFactory). So it doesn't cache all the data, only the data associated with that transaction within the scope of that entity manager and then there's equality check using hashcode and equals so it won't cache duplicates.
Hibernate 1st Level Cache Explained!
22:37
TheCodeAlchemist
Рет қаралды 628
Spring Bean Factory & Application Context
13:53
Miss Xing (邢老师)
Рет қаралды 25 М.
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
JPA/Hibernate Fundamentals 2023 - Lesson 1 - Entities
1:05:22
Laur Spilca
Рет қаралды 39 М.
Zig For the Uninitiated: Zig Interfaces
11:56
Tyler Calder
Рет қаралды 3,4 М.
Spring boot JPA Architecture
12:47
Shrayansh Jain
Рет қаралды 2,7 М.
Persistence Context
5:46
Miss Xing (邢老师)
Рет қаралды 5 М.
Spring Boot Transaction Management With Propagation
27:39
Gain Java Knowledge
Рет қаралды 23 М.
Spring Data JPA -Criteria Queries - The Full Guide
30:07
Bouali Ali
Рет қаралды 48 М.
shocking end 🥴🤯 LeoNata family #shorts TikTok
0:54
LeoNata Family
Рет қаралды 41 МЛН
Pixel 7 и 7 Pro с Face ID - лучше iPhone 14 Pro!
21:12
Rozetked
Рет қаралды 457 М.
Monster My Best Friend 🥹❤️👻 #shorts Tiktok
1:01
BETER BÖCÜK
Рет қаралды 29 МЛН