Spring Data MCQ

Welcome to the Spring Data MCQ (Multiple Choice Questions) guide, Here, we present a set of MCQ questions to test your knowledge of Spring Data and its sub-modules.

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

1. What does Spring Data primarily aim to provide?

a) Web service endpoints
b) Data validation tools
c) Data-access patterns implementation
d) Deployment mechanisms

Answer:

c) Data-access patterns implementation

Explanation:

Spring Data's primary goal is to provide an implementation for data access patterns, reducing boilerplate code and simplifying data access.

2. The @Query annotation in Spring Data is used to:

a) Configure the data source
b) Define custom queries
c) Automate transaction management
d) Specify the primary key field

Answer:

b) Define custom queries

Explanation:

The @Query annotation is used to specify custom queries directly within repository interfaces.

3. To expose repository methods as REST endpoints, you would use:

a) Spring Data REST
b) Spring Data JPA
c) Spring Data JDBC
d) Spring Data Web

Answer:

a) Spring Data REST

Explanation:

Spring Data REST allows you to expose CRUD operations on repository entities directly as REST endpoints.

4. Which of the following Spring Data projects supports Reactive Programming?

a) Spring Data JPA
b) Spring Data JDBC
c) Spring Data R2DBC
d) Spring Data Commons

Answer:

c) Spring Data R2DBC

Explanation:

Spring Data R2DBC provides reactive programming support for relational databases.

5. In Spring Data, which annotation is used to indicate a field as the primary key?

a) @PrimaryKey
b) @Id
c) @Key
d) @EntityId

Answer:

b) @Id

Explanation:

The @Id annotation is used to denote a field in the domain class as the primary key.

6. Which Spring Data module provides support for Apache Cassandra?

a) Spring Data Cassandra
b) Spring Data NoSQL
c) Spring Data Commons
d) Spring Data KeyValue

Answer:

a) Spring Data Cassandra

Explanation:

Spring Data Cassandra provides easy configuration and access to Apache Cassandra.

7. For defining derived delete queries in Spring Data, which keyword can be used within method names?

a) RemoveBy
b) DeleteFrom
c) EraseBy
d) DeleteBy

Answer:

d) DeleteBy

Explanation:

You can define derived delete queries using the DeleteBy keyword in method names.

8. The @EnableJpaRepositories annotation is used to:

a) Enable Spring Security for JPA repositories
b) Activate Spring Data JPA repositories
c) Enable JPA's second-level cache
d) Initialize JPA EntityManager

Answer:

b) Activate Spring Data JPA repositories

Explanation:

@EnableJpaRepositories is used to activate Spring Data JPA repositories in the application.

9. What does the @Transactional annotation do in Spring Data?

a) Makes a method run within a database transaction
b) Ensures data integrity
c) Provides isolation between concurrent transactions
d) All of the above

Answer:

d) All of the above

Explanation:

The @Transactional annotation ensures that a method runs within a transactional context, providing features like data integrity and isolation.

10. In Spring Data, what is a Projection?

a) A database view
b) A 3D representation of data
c) A subset of attributes of an entity
d) A replication of the database

Answer:

c) A subset of attributes of an entity

Explanation:

Projections in Spring Data provide a way to retrieve a subset of attributes of an entity or DTOs (Data Transfer Objects).

11. The @Modifying annotation in Spring Data is typically used with:

a) SELECT queries
b) DELETE or UPDATE queries
c) Stored procedures
d) @Entity beans

Answer:

b) DELETE or UPDATE queries

Explanation:

The @Modifying annotation is used to highlight that a query changes the data in the database, typically with DELETE or UPDATE operations.

12. For which of the following databases does Spring Data NOT offer dedicated support?

a) MongoDB
b) Redis
c) Neo4j
d) SQLite

Answer:

d) SQLite

Explanation:

While Spring Data offers specialized modules for MongoDB, Redis, and Neo4j, there isn't a dedicated module for SQLite.

13. The @LastModifiedDate annotation in Spring Data is useful for tracking...

a) Entity creation dates
b) Entity modification dates
c) Entity access dates
d) Entity deletion dates

Answer:

b) Entity modification dates

Explanation:

The @LastModifiedDate annotation helps in tracking the last modified date of an entity.

14. Which annotation is used to mark a method to execute a native SQL query in Spring Data JPA?

a) @SQLQuery
b) @ExecuteSQL
c) @NativeQuery
d) @Query(nativeQuery = true)

Answer:

d) @Query(nativeQuery = true)

Explanation:

The @Query annotation with nativeQuery = true is used to execute native SQL queries.

15. Which annotation is used to denote a named query in Spring Data JPA?

a) @NamedQuery
b) @NameQuery
c) @SelectQuery
d) @FindQuery

Answer:

a) @NamedQuery

Explanation:

The @NamedQuery annotation is used to define named queries in JPA.



Comments