Lecture 4A Flashcards

1
Q

What is a an embedded id?

A

Entire object in a field is used as primary key: @EmbeddedId DependentId id; A variant of composite key. Also original class must be @Embeddable

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

How to auto generate id

A

@Id @GeneratedValue

Int id;

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

How update existing entity?

A

em.merge(customer);
If there’s already a customer with same primary key merge updates it, otherwise it persists it. Must be embedded in transaction.

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

Explain process of em.find(customer.getClass(), id);

A

If class and id refers to an entity currently in PC this entity is returned from cache. If the entity is not in PC but is in database a new managed object is created in PC and returned. Otherwise null is returned.

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

How to write compound primary key in JPA?

A

@Id int id;

@Id String name;

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

JPQL ?

A

Java Persistence Query Language. Allows for more sophisticated queries. Based on older Hibernate Query Language. Operates on entities(objects) rather than tables.

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

Do basic JOQL search

A

SELECT c FROM Country c

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

Do JPQL queries need a transaction?

A

No. Example: Query myQuery = em.createQuery(“SELECT c FROM Country c”);
List results = query.getResultList();

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

How to make a query typed?

A

TypedQuery q = em.cresteQuery(“SELECT c FROM Country c”);

List results = q.getResultList();

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