Hibernate Flashcards
Merge vs Update (hibernate)
update can fail if an instance of the object is already in the session.
Merge should be used in that case
flush vs commit
session.flush() communicates a series of operations to the database (insert, update, delete).
The database maintains them as pending operations in a transaction.
The changes aren’t persisted permanently to disk, or visible to other transactions until the database receives a COMMIT
Concept of JPA (entity manager,
persistence context, persistence
unit)
specification that defines the management of relational data in a Java application
Entity Manager: Manages entities and handles database operations in JPA.
Persistence Context: The cache that holds managed entities within a transaction.
Persistence Unit: A configuration unit that defines database connection settings and entity classes for JPA.
get vs load (hibernate)
Get() returns the object by fetching it from database
or from hibernate cache whereas load() just returns
the reference of an object that might not actually exist
entity states in Hibernate
New - no mapped to db row
Persistent - associated with db row
Detached - is in db, but not in session. any changed will not affect db
Removed - still in session, waiting for pysical remove
Collection types in Hibernate
same + bag
Caching levels Hibernate
session cache
Second Level Cache - when objects loaded by PK
query cache
FetchMode
fetchmode - defines how hibernate will fetch data from db
SELECT - creates small queries
BatchSize - fixed data set
JOIN - produce duplicates, but 1 query