DB Flashcards
требования к Entity
- @Entity
- public or protected no-argument constructor
- not final class methods fields
- fields not public
жц Entity
There are mainly four states of the Hibernate Lifecycle :
Transient State
Persistent State
Detached State
Removed State
Cascade
CascadeType.ALL
PERSIST
MERGE
REMOVE
REFRESH
DETACH
ACID
Атомарность (Atomicity) - все операции транзакции должны быть выполнены или не выполнены вообще.
Согласованность (Consistency) - транзакция должна приводить базу данных в согласованное состояние.
Изолированность (Isolation) - каждая транзакция должна работать в изолированном режиме, т.е. изменения, внесенные одной транзакцией, не должны видны другим транзакциям до тех пор, пока первая транзакция не будет завершена.
Долговечность (Durability) - после успешного завершения транзакции изменения должны сохраняться в базе данных.
Transaction read phenomena
dirty
non repeatable
phantom
Isolation
Read Uncommitted
Read Committed - Postgres, Oracle
Repeatable Read - MySql
Serializable
как реализуются условия в SpringData repository
- имя метода
- @Query
- Specification
transaction propagation
- REQUIRED is the default
- SUPPORTS, Spring first checks if an active transaction exists. If a transaction exists, then the existing transaction will be used. If there isn’t a transaction, it is executed non-transactional:
- MANDATORY, if there is an active transaction, then it will be used. If there isn’t an active transaction, then Spring throws an exception
- NEVER propagation, Spring throws an exception if there’s an active transaction:
- NOT_SUPPORTED If a current transaction exists, first Spring suspends it, and then the business logic is executed without a transaction
- REQUIRES_NEW, Spring suspends the current transaction if it exists, and then creates a new one
- NESTED propagation, Spring checks if a transaction exists, and if so, it marks a save point. This means that if our business logic execution throws an exception, then the transaction rollbacks to this save point. If there’s no active transaction, it works like REQUIRED
n+1
The N+1 problem is the situation when, for a single request, for example, fetching Users, we make additional requests for each User to get their information.
Eager Fetch, JOIN FETCH
Creating separate methods, SQL and JPQL queries can help tailor them for each case.
hibernate assertSelectCount(1)
Join types
INNER JOIN, OUTER JOIN, CROSS JOIN, and SELF JOIN