Andrew Golovko
@andrewgolovko
Blog of a self-taught programmer writing about the experience, tips and other stuff
153 posts
JDBC, Transactions, Spring Data JPA

M03 Q29 What is @Query used for?

@Query annotation can be used on top of Repository method, and with it you can specify query that should be used by JPA. When declaring one on top of finder method, specified query will be used, instead of generating one automatically based on finder method name.

M03 Q28 How are Spring Data repositories implemented by Spring at runtime?

Spring Repositories are implemented at runtime by SimpleJpaRepository by default

M03 Q27 What is the naming convention for finder methods in a Repository interface?

limit – result of the query can be limited by usage of first/top keyword

M03 Q26 How do you define a Repository interface? Why is it an interface not a class?

To define Repository interface, you need to follow those steps:

M03 Q25 What is a Repository interface?

Repository interface is a Java interface that describes DAO with expected behaviors, based on which Spring Data will automatically generate DAO logic. Repository interface takes Domain Class and ID of type to manage.

M03 Q24 What do you have to configure to use JPA with Spring? How does Spring Boot make this easier?

Following steps are required to work with JPA in Spring Framework:

M03 Q23 Which PlatformTransactionManager(s) can you use with JPA?

JPA can work with following transaction managers:

M03 Q22 Are you able to participate in a given transaction in Spring while working with JPA?

Yes, JPA in Spring uses JpaTransactionManager, which supports cases when DataSource is used directly, so it allows mixing JPA and JDBC code under one transaction.

M03 Q21 What do you need to do in Spring if you would like to work with JPA?

Following steps are required to work with JPA in Spring Framework:

M03 Q20 Why is the term "unit of work" so important and why does JDBC AutoCommit violate this pattern?

Unit of work is a generic term to describe, set of tasks that are performing some changes on the data, with assumption that all changes needs to be performed, or no changes should be performed at all.