Java How to Program, 10/e Multiple Choice Test Bank Page 1 of
5
Java Persistence API (JPA)
29.1 Introduction
29.1 Q1: Which of the following statements related to JPA is false?
a. The Java Persistence API (JPA) maps Java classes to relational database tables
and objects of those classes to rows in the tables. This is known as ob-
ject-relational mapping.
b. You can use the NetBeans IDE’s object-relational mapping tools to select a
database and autogenerate classes that use JPA to interact with that database.
Your programs can then use those classes to query the database, insert new
records, update existing records and delete records.
c. Unlike JDBC, you will have to create mappings between your Java code and
database tables, and you’ll be able to perform complex database manipulations
directly in Java.
d. JPA can be used with any database management system that supports JDBC.
29.2 JPA Technology Overview
29.2 Q1: When you used JPA in this chapter, you interacted with an existing da-
tabase via classes that the NetBeans IDE generated from the database’s schema.
You used the NetBeans Entity Classes from Database… option to add to your project
classes that represented the database tables. Together, these classes and the
corresponding settings are known as a ________ unit.
a. perseverance
b. perpetual
c. sticky
d. persistence.
29.2.2 The javax.persistence Package
29.2.2 Q1: An object that implements the EntityManager ________ manages the
interactions between a program and the database.
a. interface
b. class
c. enumeration
Java How to Program, 10/e Multiple Choice Test Bank Page 2 of
5
d. None of the above.
29.2.2 Q2: Which of the following JPA-related statements in false?
a. An object that implements the TypedQuery generic interface performs que-
ries and returns a collection of matching entities.
b. To create queries, you can use EntityManager methods.
c. The Java Persistence Query Language (JPQL) is quite similar to SQL.
d. JPQL is optimized for dealing with relational database tables, rather than en-
tity objects.
29.2.2 Q3: When you define a query in your own code, it’s known as a(n) ________
query.
a. dynamic
b. static
c. active
d. passive
29.3 Querying a Database with JPA
29.3.4 Adding the JPA and Java DB Libraries
29.3.4 Q1: Which of the following statements is false?
a. For certain types of projects, NetBeans automatically includes JPA support,
but not for simple Java Application projects.
b. NetBeans projects do not include database drivers by default.
c. Each Java Enterprise Edition (Java EE) API—such as JPA—has a reference im-
plementation that you can use to experiment with the API’s features and imple-
ment applications.
d. The JPA reference implementation—which is included with the NetBeans Java
EE version—is NetBeansLink.
Java How to Program, 10/e Multiple Choice Test Bank Page 4 of
5
d. None of the above.
29.3.7 Q3: The JPA annotation @Basic specifies whether the column is optional
and whether the corresponding data should loaded ________ (i.e., only when the
data is accessed through the entity object) or ________ (i.e., loaded immediately
when the entity object is created).
a. lazily, actively
b. slowly, eagerly
c. lazily, eagerly
d. idly, actively
29.5 Address Book: Using JPA and Transactions to
Modify a Database
29.5.1 Transaction Processing
29.5.1 Q1: which of the following statements about JPA database transaction
processing is false?
a. Transaction processing enables a program that interacts with a database to
treat a set of operations as a single operation. Such an operation also is known
as an atomic operation or a transaction.
b. At the end of a transaction, a decision can be made either to commit the
transaction or roll back the transaction.
c. Committing a transaction finalizes the database operation(s); all insertions,
updates and deletions performed as part of the transaction cannot be reversed.
d. Rolling back the transaction leaves the database in its state prior to the data-
base operation. This is useful when a portion of a transaction fails to complete
properly.
29.5.1 Q2: In JPA transaction processing, if the operations execute successfully,
you call EntityTransaction method _______ to commit the changes to the da-
tabase. If any operation fails, you call EntityTransaction method ________ to
return the database to its state prior to the transaction.
Java How to Program, 10/e Multiple Choice Test Bank Page 5 of
5
a. apply, rollback
b. commit, restore
c. apply, restore
d. commit, rollback
29.5.4 AddressBook Class
29.5.4 Q1: Which f the following JPA-related statements is false?
a. You can use EntityManager method getTransaction to get the Enti-
tyTransaction that manages the transaction.
b. You can use EntityTransaction method begin to start the transaction.
c. You can use EntityManager method apply to insert a new entity into the
database.
d. You call EntityTransaction method commit to commit the changes to the
database.
29.5.5 Other JPA Operations
29.5.5 Q1: Which of the following JPA-related statements is false?
a. You can update an existing entity by modifying its entity object in the context
of a transaction.
b. Once a transaction is committed, the changes to the entity are saved to the
database.
c. You can delete an existing entity.
d. When you commit a transaction the entity is kept as a backup in the database.