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 ____?

  1. Java persistence API
  2. Java programming API
  3. Java persistence Arguments

Answer: A) Java persistence API

Explanation:

JPA stands for Java persistence API.

Discuss this Question


2. JPA is used for ____?

  1. For data access, persistence, and management in Java applications
  2. For testing java applications
  3. For creating runtime API
  4. 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.

  1. Persistence
  2. Entity
  3. Primary key
  4. 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.

  1. Persistence
  2. Entity
  3. EntityManager
  4. 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?

  1. Transactions
  2. Entity
  3. Primary key
  4. 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?

  1. Yes
  2. 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?

  1. @Join
  2. @Column
  3. @JoinColumn
  4. 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?

  1. @list
  2. @NamedQuery
  3. @NamedQueries
  4. @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?

  1. @list
  2. @NamedQuery
  3. @NamedQueries
  4. @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?

  1. @pk
  2. @primary
  3. @key
  4. @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.

  1. ORM
  2. JPA
  3. JRE
  4. 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?

  1. @table
  2. @entitymanager
  3. @entityfactory
  4. @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?

  1. Object relationship mapping
  2. Object-oriented relationship map
  3. Originator relationship mapper
  4. 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?

  1. One-to-one
  2. Many-to-one
  3. 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?

  1. One-to-one
  2. Many-to-one
  3. 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?

  1. One-to-one
  2. Many-to-one
  3. 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?

  1. One-to-one
  2. Many-to-one
  3. 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.

  1. Entity
  2. EntityManagerFactory
  3. EntityManager
  4. 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.

  1. Entity
  2. EntityManagerFactory
  3. EntityManager
  4. 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?

  1. MVC
  2. Layered architecture
  3. MVVM
  4. 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?

  1. 5
  2. 8
  3. 4
  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?

  1. Yes
  2. 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.

  1. Eager fetch
  2. 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?

  1. Eager fetch
  2. 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?

  1. 2
  2. 3
  3. 4
  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.

  1. JPA API
  2. Persistence Objects
  3. ORM
  4. 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?

  1. Java Programming Querying Language
  2. Java Programs Query Language
  3. 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 ____?

  1. with Captial lettered 'Set'
  2. with small lettered 'set'
  3. 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 ____?

  1. with Captial lettered 'Get'
  2. with small lettered 'get'
  3. 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 ____.

  1. Object
  2. Instance
  3. Persistence Class
  4. 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.

  1. Eager Fetch
  2. 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?

  1. Table per class strategy
  2. Joined table strategy
  3. 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.

  1. Table per class strategy
  2. Joined table strategy
  3. 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?

  1. @ManyToOne Relation
  2. @OneToMany Relation
  3. @OneToOne Relation
  4. @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?

  1. @ManyToOne Relation
  2. @OneToMany Relation
  3. @OneToOne Relation
  4. @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.

  1. @ManyToOne Relation
  2. @OneToMany Relation
  3. @OneToOne Relation
  4. @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?

  1. 5
  2. 4
  3. 2
  4. 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?

  1. First-level cache
  2. 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?

  1. First-level cache
  2. 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.

  1. Table per class strategy
  2. Joined table strategy
  3. Single table strategy
  4. 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





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.