WorksheetsSpring Data JPA
Total questions: 20
Worksheet time: 10mins
What is the main goal of Object-Relational Mapping (ORM)?
Encrypt data in the database
Map Java objects to database tables
Convert Java to SQL manually
Replace SQL completely
Which annotation is used to mark a class as a JPA entity?
@Bean
@Entity
@Component
@Table
What does @Table(name="employee") specify in an entity class?
Database name
Column name
Table name
Schema name
What is the purpose of @Column(name="emp_id")?
It maps an entity to a table
It maps a field to a specific column in the table
It sets primary key
It defines table constraints
Which annotation marks a field as the primary key in a JPA entity?
@Column
@GeneratedValue
@Id
@PrimaryKey
Which JPA strategy allows the database to automatically generate primary key values?
AUTO_INCREMENT
@Generated
GenerationType.IDENTITY
@AutoKey
Which method in EntityManager is used to save a new entity to the database?
store()
insert()
persist()
save()
What does the EntityManager.find() method do?
Deletes the entity
Retrieves an entity by its primary key
Updates the entity
Maps table to class
Which of the following is NOT a valid GenerationType in JPA?
IDENTITY
AUTO
SEQUENCE
UUID
What is the default fetch type for @ManyToOne relationships in JPA?
LAZY
EAGER
DEFAULT
NONE
What is the main difference between JPA and Hibernate?
JPA is a framework, Hibernate is a specification
JPA is a specification, Hibernate is its implementation
JPA is used in Python, Hibernate in Java
No difference
What does @Bean annotation do in Spring context?
Declares a component
Marks a method to return a bean managed by Spring
Maps a column to a class
Declares a service
What is the scope of an entity in Hibernate once persisted using EntityManager?
JVM-wide
Global
Attached to the persistence context
Stateless
What is the purpose of @GeneratedValue(strategy = GenerationType.IDENTITY)?
Uses application to generate the primary key
Allows the database to auto-generate primary key using identity column
Uses UUID for key generation
Automatically generates unique constraint
What type of relationship is defined by @OneToMany annotation?
One object can map to many rows
Many classes mapped to one table
One entity is related to many instances of another entity
One column to many columns
What does @Entity annotation require to work correctly?
A @Column on each field
A class-level @Table
A field with @Id
A no-argument constructor
Which of the following is true about EntityManager?
It is part of Spring Boot
It is a Hibernate-only feature
It manages the lifecycle of entities
It is used only for JDBC
What does ORM stand for?
Object Relational Mapper
Object Resource Method
Oracle Relational Model
Object Repository Manager
In which package is @Entity annotation located?
org.springframework.stereotype
org.hibernate.annotations
javax.persistence
java.persistence.entity
Which interface provides CRUD operations in JPA?
CrudInterface
EntityManager
JdbcTemplate
JpaEntity
