Spring Boot Data Access MCQ - Multiple Choice Questions and Answers

Welcome to the  Spring Boot Data Access MCQ (Multiple Choice Questions) guide. Here, we present a set of MCQ questions to test your knowledge of Spring Boot Data Access.

Note that each question is followed by the correct answer and an explanation to help reinforce your knowledge.

1. Which starter dependency is typically added for JPA-based applications in Spring Boot?

a) spring-boot-starter-web
b) spring-boot-starter-data-jdbc
c) spring-boot-starter-data-jpa
d) spring-boot-starter-hibernate

Answer:

c) spring-boot-starter-data-jpa

Explanation:

The spring-boot-starter-data-jpa dependency provides all the necessary functionalities to develop JPA-based applications with Spring Boot.

2. In Spring Boot, which interface primarily facilitates CRUD operations?

a) Repository
b) CrudRepository
c) JpaRepository
d) HibernateRepository

Answer:

b) CrudRepository

Explanation:

CrudRepository provides a generic CRUD operation on a repository for a specific type.

3. Which annotation is used to indicate a JPA entity in Spring Boot?

a) @EntityBean
b) @JpaEntity
c) @Entity
d) @TableEntity

Answer:

c) @Entity

Explanation:

The @Entity annotation is used to indicate that a class is a JPA entity.

4. How do you define a custom query method in a Spring Data repository?

a) @QueryMethod
b) @CustomQuery
c) @Select
d) @Query

Answer:

d) @Query

Explanation:

The @Query annotation allows for defining custom queries directly in the repository interface.

5. Which annotation is used to auto-wire a repository in a Spring Boot service or controller?

a) @Inject
b) @Autowired
c) @Resource
d) @Include

Answer:

b) @Autowired

Explanation:

The @Autowired annotation is used for automatic dependency injection.

6. To perform paging and sorting in Spring Data, which interface should the repository extend?

a) PageableRepository
b) SortingRepository
c) PagingRepository
d) PagingAndSortingRepository

Answer:

d) PagingAndSortingRepository

Explanation:

The PagingAndSortingRepository provides methods to perform paging and sorting of records.

7. Which annotation is used to denote a transactional boundary in Spring Boot?

a) @Transaction
b) @Transact
c) @Transactional
d) @TransactionBoundary

Answer:

c) @Transactional

Explanation:

The @Transactional annotation is used to define the scope of a single database transaction.

8. Which property helps define the DDL (Data Definition Language) auto-generation strategy in Spring Boot?

a) spring.jpa.hibernate.ddl-auto
b) spring.data.jpa.ddl-auto
c) spring.jpa.data.ddl-auto
d) spring.jpa.ddl.strategy

Answer:

a) spring.jpa.hibernate.ddl-auto

Explanation:

The property spring.jpa.hibernate.ddl-auto determines the auto-generation strategy for DDL.

9. How can you define a named native query in a JPA Entity?

a) @NativeQuery
b) @NamedQuery
c) @NameNativeQuery
d) @JpaNativeQuery

Answer:

c) @NameNativeQuery

Explanation:

The @NameNativeQuery annotation is used to specify a named native SQL query.

10. Which of the following is the default database connection pool in Spring Boot 2.x?

a) C3P0
b) DBCP
c) HikariCP
d) BoneCP

Answer:

c) HikariCP

Explanation:

Starting from Spring Boot 2.x, HikariCP is the default connection pool.

11. Which interface primarily facilitates custom query method implementations?

a) JpaSpecificationExecutor
b) CustomRepository
c) QueryDslExecutor
d) RepositoryCustom

Answer:

a) JpaSpecificationExecutor

Explanation:

The JpaSpecificationExecutor interface allows for the creation of custom query methods using the criteria API.

12. To configure the number of connections in the HikariCP pool, which property is used?

a) spring.datasource.hikari.maximumPoolSize
b) spring.datasource.hikari.maxConnections
c) spring.datasource.connections.max
d) spring.hikari.maxPoolSize

Answer:

a) spring.datasource.hikari.maximumPoolSize

Explanation:

The spring.datasource.hikari.maximumPoolSize property determines the maximum number of connections in the HikariCP pool.


Related Spring Boot MCQ Posts

Comments