Lecture 8 - Session Beans and Jakarta Persistence (Intro to EJB) Flashcards

1
Q

What is a Jakarta Enterprise Bean (EJB) and what services does it provide?

A

A bean that can be used for business logic:
- Concurrency
- Transaction management
- Persistence
- Security etc.

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

What are the 3 types of EJBs?

A

Session beans (business behaviour, 1 client at a time)
@Stateless, @Stateful, @Singleton

Message-driven beans (async messages, methods are normally synchronous)
@MessageDriven

Entity beans (persist in DB, multiple clients at a time)
@Entity

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

Why use EJB over CDI bean?

A

Transactions + security controls for methods

Automatic concurrency

Instance pooling -> stateless beans can be shared

Passivation -> Stateful beans can be temp stored in memory when not needed

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

Difference between stateless and stateful session beans?

A

Stateless beans are short-lived and not persistent (independent method calls).

Stateful session beans hold client information between method calls.

NOTE: singleton beans are useful for application-wide shared resources. Must be thread-safe/concurrent

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

What are entity beans?

A

EJB bean that has persistent state

can be used by multiple clients at a time

Replaced by jakarta persistence (don’t depend on EJB container, less boilerplate)

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

What are EJB session beans?

A

Interact with single client at a time.

Stateful session beans should be serializable

Relatively short lived (represents chunk of application logic)

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

What is Jakarta Persistence?

A

Java classes with annotations

EntityManager manages beans that are attached:
- create
- find
- update
- delete

changes to attached beans tracked and saved to DB

detached beans are regular java objects that can be sent across the network/application as data transfer objects

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

What is Object-to-relational persistence?

A

mapping object fields to a relational database using EJB 3 standard - Object-Relational Mapping (ORM)

Fields annotated with @Id represent PK
(Normally have @Column annotation as well)

Fields annotated with @Column(name=”someName”) maps field to a column in DB

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

An entity bean is defined for each table (T or F)

A

T
(Multiple rows are created and mapped to multiple instances)

(CRUD operations from Entity manager manipulate these instances)

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

Annotations for Jakarta persistence (Entity bean, ID - primary key, Table, Column )

A

@jakarta.persistence.*

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

What is persistence.xml?

A

Lives in META-INF
Specifies name of persistence unit (configure how application connects to DB)
Specifies reference to data source (inside <persistence-unit>)
May specify vendor-specific options</persistence-unit>

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