Skip to content

Merge Add bookings#2

Merged
zephyr0021 merged 14 commits intomainfrom
add-bookings
Jun 25, 2025
Merged

Merge Add bookings#2
zephyr0021 merged 14 commits intomainfrom
add-bookings

Conversation

@zephyr0021
Copy link
Owner

Выполнил ТЗ 15 спринта

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class UserValidationService {
Copy link

Choose a reason for hiding this comment

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

сервис можно переместить из пакета model к другим сервисам

возможно, если метод только один, будет удобнее перенести метод в UserService

Copy link
Owner Author

Choose a reason for hiding this comment

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

перенес. Решил сделать отдельный сервис, потому что еще используется в других сервисах


@Entity
@Table(name = "bookings")
@Data
Copy link

Choose a reason for hiding this comment

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

На дипломе будут рекомендовать не использовать Data с сущностями, статьи про это

https://thorben-janssen.com/lombok-hibernate-how-to-avoid-common-pitfalls/

https://habr.com/ru/companies/haulmont/articles/564682/

https://jpa-buddy.com/blog/hopefully-the-final-article-about-equals-and-hashcode-for-jpa-entities-with-db-generated-ids/

Воспроизвести одну из проблем, которую описывают в статьях, можно так

  • метод не помечаем Transactional
  • вызываем сущность через getById
  • пытаемся вызвать toString()
  • получаем LazyInitializationException

Из-за того, что нет аннотации Transactional, транзакция открывается и сразу закрывается на вызове findById.
Далее пытаемся сделать toString(), и hibernate попытается дозапросить информацию по Lazy полям, что приведет к исключению LazyInitializationException, так как транзакция уже закрыта

Copy link
Owner Author

Choose a reason for hiding this comment

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

Поправил

@zephyr0021 zephyr0021 merged commit 076fe10 into main Jun 25, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants