.Other tip, merge don't update database, the only function for merge is to bring de entity object to persistent context.
EntityManager.merge updates the database with the data held in the entity,
leonardo segala wrote:
Other tip, merge don't update database, the only function for merge is to bring de entity object to
SCJP 5.0, SCWCD 5.0, SCBCD 5.0, SCEA/OCMJEA 5.0
Tyronne Fernando wrote:
According to the given code sample (ie. undoItemChanges() method), does the merge() method call will be over-written by the call to the refresh() method before they get executed on the database? That means the merge() method will not get executed on the database at all, which will stop updating the item record in the database.
Otherwise if the merge() get executed first and the refresh() get executed after on the database will the following scenario could happen? Let say the item object was already modified (different from the database record) while it was detached. When we execute merge() it will update the databse with the changes. When we call refresh() it will update the item object with latest data from the database. The state of the item object will be the same as before we executed undoItemChanges(). If this happens the undoItemChanges() method functionality will not be correct.
Thanks in advance.
SCJP, SCJD, SCWCD, OCPJBCD
Mihai Radulescu wrote:Hi
The key for the "entityManager.refresh(entityManager.merge(item))" is the "flush". In this example everything is done in the same transaction (and no coresp. query are done), this is the reason why the merge only attach the given entity to the actual context after this the refresh get the database information and put it in the managed entity - the database contains the information committed with the last transaction.
Regards,
Mihai
SCJP, SCWCD, SCBCD
SCJP, SCJD, SCWCD, OCPJBCD
Mihai Radulescu wrote:
1. attach your entity to the persistence context (merge) so you have an entity in the persistence context cache but you don't flush the cache.
SCJP, SCWCD, SCBCD
SCJP, SCJD, SCWCD, OCPJBCD
Mihai Radulescu wrote:
so the sync process does not alter the database row, if the row is not altered then also the version remains the same.
SCJP, SCWCD, SCBCD
SCJP 5.0, SCWCD 5.0, SCBCD 5.0
ryan sukale wrote:In the undoItemChanges method, our objective is to make the entity managed, and then load the data from the database into our entity instance. Why do we need to do a merge here? We can simply call the find() method, which willl solve our problem of making the entity managed, and then we can return the managed instance.
SCJP, SCWCD, SCBCD
SCJP, SCJD, SCWCD, OCPJBCD
Mihai Radulescu wrote:
Jisha, I just do a small research - the merge generates an UPDATE and update increase the version even if the erst of the row remains the same. I will review the specification to be shore.
SCJP, SCWCD, SCBCD
SCJP, SCJD, SCWCD, OCPJBCD
Mihai Radulescu wrote:No, I don't think that the database will roll back, the update will alter the needed rows even it the contains remain the same. The version will be increase also.
SCJP, SCWCD, SCBCD
SCJP, SCJD, SCWCD, OCPJBCD
Mihai Radulescu wrote:
under some circumstances is good to sacrifice the design for performance.
SCJP, SCWCD, SCBCD
Don't get me started about those stupid light bulbs. |