-
Notifications
You must be signed in to change notification settings - Fork 25
Completed solution #1
base: master
Are you sure you want to change the base?
Conversation
# Conflicts: # employee-profile/src/main/java/com/bobocode/model/Employee.java # employee-profile/src/main/java/com/bobocode/model/EmployeeProfile.java
# Conflicts: # photo-comment-dao/src/main/java/com/bobocode/dao/PhotoDaoImpl.java # photo-comment-dao/src/main/java/com/bobocode/model/Photo.java
# Conflicts: # employee-profile/src/main/java/com/bobocode/model/Employee.java # photo-comment-dao/src/main/java/com/bobocode/model/PhotoComment.java
} | ||
|
||
@Override | ||
public void update(Account account) { | ||
throw new UnsupportedOperationException("I don't wanna work without implementation!"); // todo | ||
performWithinPersistenceContext(em -> em.merge(account)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Хочу уточнить, Merge вроде как возвращает объект с базы в persistence context, а как он выполняет апдейт с его помощью?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since provided account is in the detached state (it has an id, and is not loaded to the Persistence Context), Hibernate will call the database to load this account by its id first. Then it will copy data from account you provided onto loaded account. So, if the account you provided has some fields changed, these changes will be applied to the loaded account, and since loaded account is changed in the scope of a persistence context, dirty checking will call database to perform an update.
# Conflicts: # company-products/src/main/java/com/bobocode/model/Product.java
# Conflicts: # author-book/src/main/java/com/bobocode/model/Book.java
This pull request is created in order to discuss the completed solution of the exercises. Feel free to ask any questions by adding comments to the PR ➕