Week 4 - Entity Manager Flashcards

1
Q

What is ORM?

A

Object-to-relational mapping, Jakarta persistence maps objects to a relational database.

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

What are entities?

A

POJOs that may be managed.

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

What is an entity manager?

A

The central service for persistence actions.

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

What is the difference between a managed and unmanaged entity bean?

A

A managed entity bean is synchronized with the database.

An unmanaged entity bean is independent from the database.

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

What are the 2 types of persistence context?

A

Transaction-scoped and extended.

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

What is transaction-scoped persistence context?

A

Rely on container to manage transactions.
Open for single transactions
(default for session bean methods)

@PersistenceContext

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

What is extended persistence context?

A

Requires SFSB
Context stays open for multiple transactions which reduces constant merges (extended).

@PersistenceContext(type=EXTENDED)

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

When is an entity detached/attached in a transaction-scoped persistence context?

A

Transaction-Scoped Persistence Context (Default)

Entity automatically detaches when the method returns because the persistence context is closed.

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

When a bean is detached you can use it as a POJO or a DTO (T or F)

A

T

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

How are persistence units packaged and why?

A

The persistence unit is included in an EJB module, which is then bundled into an EAR.
This allows for centralized data access logic and can be shared by multiple web modules.
It is useful for modular applications where persistence logic is separated from the web layer.

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

What is a persistence unit?

A

A persistence unit is a set of entity classes managed by JPA and mapped to a single database. It is defined in persistence.xml, which must be placed in the META-INF directory of the JAR or WAR file that contains entity classes.

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

What attribute is required for each persistence unit?

A

name

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

What entity manager method writes entity fields into the database?

A

entityManager.persist();

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

What entity manager method will retrieve an entity from the database using its primary key?

A

entityManager.find();

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

EJB uses SQL as its query language (T or F)

A

F - it uses and SQL-like query language based on entities.

Query query = entityManager.createQuery(“from “ +
“Employee e where id=2”);
Employee emp = (Employee)query.getSingleResult();

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

What does entityManager.flush() do?

A

Syncs entity beans that are managed.

17
Q

How do you manually update a detached entity?

A

EntityManager.merge(theEntity)

18
Q

EntityManager.delete() will delete an entity from the DB (T or F)

A

F - EntityManager.remove(entityObject)

19
Q

What Entity Manager method can be used to tell if an entity is managed or unmanaged?

A

contains() returns true if its argument is managed
by the persistence context

20
Q

What entity manager method detaches all managed instances from the persistence context?