Sleep – JPA dirty check
I know that JPA implementers (such as hibernate) monitor entities attached to the persistence context. If any fields of any entity are changed, the changes will be updated to the database
My question is, how does JPA track changes? The entity is not intercepted by the agent, so of course it is not intercepted by the "setter". How is it completed?
I'm interested in the implementation details of this "dirty check" function
Solution
They have done something completely implementation dependent (i.e. the JPA specification doesn't help you here)
Some implementations (such as datanucleus, openjpa) use bytecode enhancement and can effectively manage which fields are dirty since loading (and do not need to maintain a snapshot of the original field values)
Other implementations must be compared with some previous values (or by comparison with the data store)