Spring Data and Persistence Flashcards

1
Q

What is Spring Data JPA?

A

A part of Spring Data that simplifies working with JPA-based repositories by providing common CRUD operations and query methods.

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

What is the @Entity annotation in JPA?

A

It marks a class as a JPA entity mapped to a database table.

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

What is the role of @Repository in Spring Data?

A

It is used to indicate that the class provides CRUD or data manipulation operations on a database.

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

What is the @Transactional annotation used for?

A

To manage transactions declaratively in Spring.

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

How can you create a repository interface in Spring Data JPA?

A

By extending JpaRepository or CrudRepository.

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

How does Spring Data JPA handle pagination?

A

Using the Pageable interface and returning Page<T> results from repository methods.</T>

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

What is Lazy and Eager loading in JPA?

A

Lazy loading fetches data on demand, while Eager loading fetches all related entities upfront.

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

How can you define a custom query in Spring Data JPA?

A

Using the @Query annotation in repository interfaces.

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

What is the difference between save() and saveAndFlush() in Spring Data JPA?

A

save() saves an entity but may not flush it to the database immediately, while saveAndFlush() forces an immediate flush.

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

What is the purpose of the @Id annotation in JPA?

A

It marks a field as the primary key for the entity.

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