Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Completed solution #1

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open

Completed solution #1

wants to merge 47 commits into from

Conversation

tboychuk
Copy link
Collaborator

@tboychuk tboychuk commented Sep 9, 2018

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 ➕

# 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
}

@Override
public void update(Account account) {
throw new UnsupportedOperationException("I don't wanna work without implementation!"); // todo
performWithinPersistenceContext(em -> em.merge(account));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хочу уточнить, Merge вроде как возвращает объект с базы в persistence context, а как он выполняет апдейт с его помощью?

Copy link
Collaborator Author

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.

@tboychuk tboychuk changed the title Exercise/completed Completed solution Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants