JPA query to modify the data, but not saved to the database, the database has changed

Use JPA query data, to check out the results to be modified, but does not save the database, the database but eventually did the same changes.

Solution: the need to modify the value of re-copied to another object making changes.

the reason:

JPA like four life cycle shown on:

New: transient object, yet id, has not been established and Persistence Context associated with the object.
Managed: persistent managed objects, have an id value, has been established and Persistence Context associated with the object.
Datached: offline objects free state, has an id value, but without creating objects and Persistence Context associated.
Removed: delete objects have an id value, being evil, and Persistence Context associated, but is ready to be removed from the database
when data is retrieved from the database, because there are transaction management, so the data has been associated with the session, and database data, has been a persistent and cache among the database when we make changes to check out the data, cache data in the cache Session is changed, then the database will follow then make the appropriate changes. So automatically execute the update of the update operation.


----------------
Disclaimer: This article is CSDN blogger "sweet little treasure" of the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source and link this statement.
Original link: https: //blog.csdn.net/nanxuan1030/article/details/82986270

Guess you like

Origin www.cnblogs.com/geass-jango/p/11567390.html