Home »
MCQs
JPA (Java Persistence API) Multiple-Choice Questions (MCQs)
JPA (Java Persistence API) is just a specification that facilitates object-relational mapping to manage relational data in Java applications. It provides a platform to work directly with objects instead of using SQL statements.
JPA (Java Persistence API) MCQs: This section contains multiple-choice questions and answers on the various topics of JPA (Java Persistence API). Practice these MCQs to test and enhance your skills on JPA (Java Persistence API).
List of JPA (Java Persistence API) MCQs
1. JPA stands for ____?
- Java persistence API
- Java programming API
- Java persistence Arguments
Answer: A) Java persistence API
Explanation:
JPA stands for Java persistence API.
Discuss this Question
2. JPA is used for ____?
- For data access, persistence, and management in Java applications
- For testing java applications
- For creating runtime API
- All of the above
Answer: A) For data access, persistence, and management in Java applications
Explanation:
JPA is used for data access, persistence, and management in Java applications.
Discuss this Question
3. A database table is represented by an ____, which is a Java class.
- Persistence
- Entity
- Primary key
- Relationships
Answer: B) Entity
Explanation:
A database table is represented by an entity, which is a Java class.
Discuss this Question
4. ____ is a class that allows you to persist, update, and delete entities.
- Persistence
- Entity
- EntityManager
- Bias
Answer: C) EntityManager
Explanation:
EntityManager is a class that allows you to persist, update, and delete entities.
Discuss this Question
5. Which of the following is an entity's unique identifier?
- Transactions
- Entity
- Primary key
- Relationships
Answer: C) Primary key
Explanation:
A primary key is an entity's unique identifier.
Discuss this Question
6. Is JPA an open-source API?
- Yes
- No
Answer: A) Yes
Explanation:
Yes, JPA is an open-source API.
Discuss this Question
7. In a relationship mapping, which of the following annotations is used to indicate the join column?
- @Join
- @Column
- @JoinColumn
- All of the above
Answer: C) @JoinColumn
Explanation:
@JoinColumn annotation is used to specify the join column in relationship mapping.
Discuss this Question
8. ____ annotation is used to specify a Query by providing a static name?
- @list
- @NamedQuery
- @NamedQueries
- @querieslist
Answer: B) @NamedQuery
Explanation:
@NamedQuery annotation is used to specify a Query by providing a static name.
Discuss this Question
9. Which of the following annotations is used to define a list of named queries?
- @list
- @NamedQuery
- @NamedQueries
- @querieslist
Answer: C) @NamedQueries
Explanation:
@NamedQueries annotation is used for specifying the list of named queries.
Discuss this Question
10. Which of the following annotations is used to indicate an entity's primary key field?
- @pk
- @primary
- @key
- @id
Answer: D) @id
Explanation:
@id annotation is used to specify the primary key field of an entity.
Discuss this Question
11. ____ is a programming capability that allows data to be converted from object type to relational type and vice versa.
- ORM
- JPA
- JRE
- Java RMI
Answer: A) ORM
Explanation:
ORM is a programming capability that allows data to be converted from object type to relational type and vice versa.
Discuss this Question
12. Which of the following annotations defines a class as an entity?
- @table
- @entitymanager
- @entityfactory
- @entity
Answer: D) @entity
Explanation:
@entity annotation is used to define a class as an entity.
Discuss this Question
13. What do you mean by ORM?
- Object relationship mapping
- Object-oriented relationship map
- Originator relationship mapper
- Object-relational mapper
Answer: D) Object-relational mapper
Explanation:
ORM stands for object-relational mapper.
Discuss this Question
14. What is the relationship between EntityManager and entity?
- One-to-one
- Many-to-one
- One-to-many
Answer: C) One-to-many
Explanation:
The relationship between EntityManager and entity is one-to-many.
Discuss this Question
15. What is the relationship between EntityManager and Query?
- One-to-one
- Many-to-one
- One-to-many
Answer: C) One-to-many
Explanation:
The relationship between EntityManager and Query is one-to-many.
Discuss this Question
16. EntityManager and EntityTransaction have a ____- relationship?
- One-to-one
- Many-to-one
- One-to-many
Answer: A) One-to-one
Explanation:
EntityManager and EntityTransaction have a one-to-one relationship.
Discuss this Question
17. EntityManagerFactory and EntityManager have which kind of relationship?
- One-to-one
- Many-to-one
- One-to-many
Answer: C) One-to-many
Explanation:
EntityManagerFactory and EntityManager have a one-to-many relationship.
Discuss this Question
18. ____ is a factory class that generates EntityManager instances.
- Entity
- EntityManagerFactory
- EntityManager
- Persistence unit
Answer: B) EntityManagerFactory
Explanation:
EntityManagerFactory is a factory class that generates EntityManager instances.
Discuss this Question
19. The ____ serves as a logical container for a collection of entity classes.
- Entity
- EntityManagerFactory
- EntityManager
- Persistence unit
Answer: D) Persistence unit
Explanation:
The persistence unit serves as a logical container for a collection of entity classes.
Discuss this Question
20. JPA is based upon which of the following architecture?
- MVC
- Layered architecture
- MVVM
- Client-server architecture
Answer: B) Layered architecture
Explanation:
JPA is based upon layered architecture.
Discuss this Question
21. JPA supports how many different inheritance strategies?
- 5
- 8
- 4
- 3
Answer: D) 3
Explanation:
JPA supports three types of inheritance strategies:SINGLE_TABLE, JOINED_TABLE, and TABLE_PER_CONCRETE_CLASS.
Discuss this Question
22. Does JPA supports object-oriented concept?
- Yes
- No
Answer: A) Yes
Explanation:
Yes, JPA support the object-oriented concept.
Discuss this Question
23. By default, the connected entities are not retrieved alongside the primary item under the ____ strategy.
- Eager fetch
- Lazy fetch.
Answer: B) Lazy fetch.
Explanation:
By default, the connected entities are not retrieved alongside the primary item under the Lazy Fetch strategy.
Discuss this Question
24. Which of the following is the default fetch strategy in JPA?
- Eager fetch
- Lazy fetch.
Answer: A) Eager fetch
Explanation:
Eager Fetch is the default fetch strategy in JPA.
Discuss this Question
25. How ways are there to fetch records from the database?
- 2
- 3
- 4
- 5
Answer: A) 2
Explanation:
There are two methods for retrieving records from a database: eager fetch and lazy fetch.
Discuss this Question
26. ____ is used to create queries against entities to store in a relational database.
- JPA API
- Persistence Objects
- ORM
- JPQL
Answer: D) JPQL
Explanation:
JPQL is used to create queries against entities to store in a relational database.
Discuss this Question
27. What is JPQL?
- Java Programming Querying Language
- Java Programs Query Language
- Java persistence Query Language
Answer: C) Java persistence Query Language
Explanation:
JPQL stands for Java Persistence Query Language.
Discuss this Question
28. Any property's Setter method should begin with ____?
- with Captial lettered 'Set'
- with small lettered 'set'
- Any letter
Answer: B) with small lettered 'set'
Explanation:
Any property's setter method should begin with a small lettered 'set'.
Discuss this Question
29. Any property's getter method should begin with ____?
- with Captial lettered 'Get'
- with small lettered 'get'
- Any letter
Answer: B) with small lettered 'get'
Explanation:
Any property's getter method should begin with a small lettered 'get'.
Discuss this Question
30. The Java class encapsulates instance data and behaviors into a single unit known as an ____.
- Object
- Instance
- Persistence Class
- Java RMI
Answer: A) Object
Explanation:
The Java class encapsulates instance data and behaviors into a single unit known as an object.
Discuss this Question
31. The related entities are obtained alongside the primary item in a single query under the ____ strategy.
- Eager Fetch
- Lazy Fetch
Answer: A) Eager Fetch
Explanation:
The related entities are obtained alongside the primary item in a single query under the Eager Fetch strategy.
Discuss this Question
32. Which of the following inheritance strategy maps all of an entity's subclasses to the same table in the database?
- Table per class strategy
- Joined table strategy
- Single table strategy
Answer: C) Single table strategy
Explanation:
Single table Strategy maps all of an entity's subclasses to the same table in the database.
Discuss this Question
33. The ____ strategy involves creating a table for each sub entity.
- Table per class strategy
- Joined table strategy
- Single table strategy
Answer: A) Table per class strategy
Explanation:
The table-per-class strategy involves creating a table for each sub-entity.
Discuss this Question
34. In what type of relationship is one entity connected with only one instance of another entity?
- @ManyToOne Relation
- @OneToMany Relation
- @OneToOne Relation
- @ManyToMany Relation
Answer: C) @OneToOne Relation
Explanation:
One entity is connected with one and only one instance of another entity in a one-to-one relationship.
Discuss this Question
35. Which of the following relationships links one entity with one or more instances of another entity?
- @ManyToOne Relation
- @OneToMany Relation
- @OneToOne Relation
- @ManyToMany Relation
Answer: B) @OneToMany Relation
Explanation:
One entity is connected with one or more instances of another entity in a one-to-many relationship.
Discuss this Question
36. Several instances of one entity are connected with many instances of another entity in a ____ relationship.
- @ManyToOne Relation
- @OneToMany Relation
- @OneToOne Relation
- @ManyToMany Relation
Answer: D) @ManyToMany Relation
Explanation:
Several instances of one entity are connected with many instances of another entity in a many-to-many relationship.
Discuss this Question
37. How many types of caching does JPA support?
- 5
- 4
- 2
- 3
Answer: C) 2
Explanation:
JPA provides two types of caching: first-level cache and second-level cache.
Discuss this Question
38. Which of the following type of cache is also known as the entity manager cache?
- First-level cache
- Second-level cache.
Answer: A) First-level cache
Explanation:
The first-level cache is also known as the entity manager cache.
Discuss this Question
39. Which of the following type of cache is active by default in JPA and cannot be disabled?
- First-level cache
- Second-level cache.
Answer: A) First-level cache
Explanation:
JPA's first-level cache is enabled by default and cannot be deactivated.
Discuss this Question
40. A superclass is defined as an object without a matching database table in ____ Inheritance, and its attributes and mappings are inherited by its subclasses.
- Table per class strategy
- Joined table strategy
- Single table strategy
- Mapped Superclass
Answer: D) Mapped Superclass
Explanation:
A superclass is defined as an object without a matching database table in Mapped Superclass Inheritance, and its attributes and mappings are inherited by its subclasses.
Discuss this Question