Hibernate Flashcards

1
Q

Merge vs Update (hibernate)

A

update can fail if an instance of the object is already in the session.
Merge should be used in that case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

flush vs commit

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Concept of JPA (entity manager,
persistence context, persistence
unit)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

get vs load (hibernate)

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

entity states in Hibernate

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Collection types in Hibernate

A

same + bag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Caching levels Hibernate

A

session cache
Second Level Cache - when objects loaded by PK
query cache

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

FetchMode

A

fetchmode - defines how hibernate will fetch data from db

SELECT - creates small queries
BatchSize - fixed data set
JOIN - produce duplicates, but 1 query

How well did you know this?
1
Not at all
2
3
4
5
Perfectly