❮ Previous Quiz
Next Quiz ❯
Welcome to our JPA (Jakarta Persistence API) quiz! In this blog post, we present a set of 20+ Multiple Choice Questions (MCQs) to test your knowledge of Jakarta Persistence API (JPA) concepts.
JPA is a standard specification that defines the Java interfaces and annotations for object-relational mapping (ORM) in Java applications. Let's put your understanding of JPA to the test and enhance your skills in Java persistence.
Learn everything about JPA: JPA Tutorial - Java Persistence API.Check out 100+ quiz questions: 100+ Quiz Questions to Test Your Java, Spring Boot, Microservices, Hibernate, REST API Skills.
1. What does JPA stand for?
a) Java Persistence API
b) Java Programming API
c) Java Platform API
d) Java Processing API
2. Which annotation is used to mark a class as an entity in JPA?
a) @Table
b) @Entity
c) @Persistence
d) @Data
3. Which annotation is used to specify the primary key of an entity in JPA?
a) @PrimaryKey
b) @Id
c) @Key
d) @Primary
4. Which annotation is used to map a field to a column in a database table in JPA?
a) @Column
b) @Field
c) @Data
d) @Map
5. What is the default fetch type for @OneToMany and @ManyToMany relationships in JPA?
a) EAGER
b) LAZY
c) IMMEDIATE
d) NONE
6. What is the purpose of the @GeneratedValue annotation in JPA?
a) To specify a generated value for a column
b) To specify a custom generator for primary keys
c) To specify that a field should not be persisted
d) To map a relationship between entities
7. Which strategy is used by default for @GeneratedValue in JPA?
a) AUTO
b) IDENTITY
c) SEQUENCE
d) TABLE
8. Which of the following annotations is used to specify a one-to-one relationship in JPA?
a) @OneToOne
b) @OneToMany
c) @ManyToOne
d) @ManyToMany
9. Which JPA annotation is used to specify a mapping to a join table?
a) @JoinTable
b) @JoinColumn
c) @MappedSuperclass
d) @Embedded
10. What does the @Transient annotation do in JPA?
a) It maps a transient field to a database column
b) It indicates that a field should not be persisted to the database
c) It marks a field as the primary key
d) It specifies a temporary table
11. Which annotation is used to define a composite primary key in JPA?
a) @Id
b) @IdClass
c) @EmbeddedId
d) Both b) and c)
12. What is the purpose of the EntityManager in JPA?
a) To manage database connections
b) To perform CRUD operations on entities
c) To handle transactions
d) All of the above
13. How do you start a transaction in JPA?
a) EntityManager.begin()
b) Transaction.begin()
c) EntityTransaction.begin()
d) EntityManagerFactory.begin()
14. Which method is used to persist an entity in JPA?
a) save()
b) persist()
c) merge()
d) store()
15. What does the merge() method do in JPA?
a) It saves a new entity
b) It updates an existing entity or saves a new one if it doesn't exist
c) It deletes an entity
d) It retrieves an entity from the database
16. Which annotation is used to define a named query in JPA?
a) @Query
b) @NamedQuery
c) @QueryDef
d) @JPQL
17. Which JPA feature allows for automatically generating schema definitions?
a) SchemaTool
b) SchemaGen
c) SchemaExporter
d) Schema Generation
18. What is JPQL in JPA?
a) A Java-based query language for operating on entities
b) A SQL-based query language for operating on tables
c) A JSON-based query language
d) A procedural query language for stored procedures
19. Which of the following is a valid JPQL query?
a) SELECT e FROM Employee e WHERE e.salary > 50000
b) SELECT * FROM Employee WHERE salary > 50000
c) SELECT e.name, e.salary FROM Employee e
d) SELECT e.name, e.salary FROM Employee
20. What is the default cascade type for relationships in JPA?
a) ALL
b) PERSIST
c) MERGE
d) NONE
Conclusion
Congratulations on completing our JPA quiz! We hope you found it informative and enjoyed testing your knowledge of JPA concepts. Learn everything about JPA: JPA Tutorial - Java Persistence API.
Check out 100+ quiz questions: 100+ Quiz Questions to Test Your Java, Spring Boot, Microservices, Hibernate, REST API Skills.
Keep exploring JPA and practicing its various features and annotations to strengthen your skills in Java persistence.
❮ Previous Quiz
Next Quiz ❯
Comments
Post a Comment
Leave Comment