JPA Certification Free Mock Exam

Question 1 of 17 [Overview of the Java Persistence API]
Select the techniques used to specify ORM information for entity classes?
Choice 1By ORM XML meta data
Choice 2By annotations
Choice 3By TEXT files
Choice 4By CSV files
Question 2 of 17 [Introducing the Auction Application]
You are assigned to develop JPA entities for an auction application. One item may have 0 or more bids.
Select correct code snippet to define this relationship.
Choice 1
@Entity
public class Bid {
@ManyToOne
private Bid bid;

@Entity
public class Item {
@OneToMany(mappedBy="bid")
private Collection<Bid> bids;

Choice 2
@Entity
public class Bid {
@ManyToOne
private Bid bid;

@Entity
public class Item {
@OneToOne(mappedBy="bid")
private Collection<Bid> bids;

Choice 3
@Entity
public class Bid {
@OneToMany
private Collection<Bid> bids;

@Entity
public class Item {
@ManyToOne(mappedBy="bids")
private Collection<Bid> bids;
Question 3 of 17 [Java Persistence API Entities]
Given the following code snippet of an EJB 3.0 entity class:
10. @Entity
11. @Table(name="EPL_TEST")
12. public class Test { .... }
You need to change the name of the database table for the Order entity from EPL_TEST to TEST, without changing the Java source code file.
Select the best option to change table name from EPL_TEST to TEST
Choice 1Override the name using the table sub element within the persistence unit's persistence.xml file.
Choice 2This is NOT possible in a portable EJB 3.0 application. The only way to change the table name is to change the Java source code file.
Choice 3Add a custommapping.xml file to the persistence unit, override the name using the table sub element, and declare custommapping.xml in the mapping-file element in orm.xml.
Choice 4Add a custommapping.xml file to the persistence unit, override the name using the table sub element, and declare custommapping.xml in the mapping-file element in persistence.xml.
Question 4 of 17 [Understanding the Entity Manager]
Which statement about entity manager is true?
Choice 1A container-managed entity manager must be a JTA entity manager.
Choice 2An entity manager injected into session beans can use either JTA or resource-local transaction control.
Choice 3An entity manager created by calling the EntityManagerFactory.createEntityManager method always uses JTA transaction control.
Choice 4 An entity manager obtained through resource injection in a stateful session bean can use a resource-local EntityTransaction for transaction control.
Question 5 of 17 [Understanding the Entity Manager]
Which two class types must be implicitly or explicitly denoted in the persistence.xml descriptor as managed persistence classes to be included within a persistence unit?
Choice 1Entity classes
Choice 2Interceptor classes
Choice 3Embedded classes
Choice 4Entity listener classes
Choice 5Helper Classes
Question 6 of 17 [Modeling Entity Relationships]
A developer from EPractize Labs wants to implement a relationship between Customer and License entity classes. Every License belongs to one Customer, and one Customer has several Licenses. In this application it is essential to quickly determine which Customer a License belongs to and to also easily access all Licenses of a given Customer.
Which two declarations provide a solution to these requirements?
Choice 1
In class License:
@ManyToOne
private Customer customer;
Choice 2
In class License
@OneToMany
private Customer customer;
Choice 3
In class License:
@OneToMany(mappedBy="license")
private Collection<Customer> customers;
Choice 4
In class Customer:
@ ManyToOne(mappedBy="customer")
private Collection<License> Licenses;
Question 7 of 17 [Modeling Entity Relationships]
The cost of retrieving and building an object's relationships, far exceeds the cost of selecting the object.
Which JPA fetching of a relationship to be deferred until it is accessed?
Choice 1EAGER
Choice 2LAZY
Question 8 of 17 [Entity Inheritance and Object-Relational Mapping]
A developer maps the abstract entity class Account with concrete entity sub-classes CreditCardAccount and SavingsAccount using the single table per class hierarchy strategy.
Which two statements are true?
Choice 1Instances of CreditCardAccount and SavingsAccount are stored in the same table.
Choice 2All columns that correspond to fields declared in Account must be defined as nullable in the database.
Choice 3The fields declared in Account are stored in a different table than the ones declared in CreditCardAccount and SavingsAccount.
Choice 4All columns that correspond to fields declared in CreditCardAccount or SavingsAccount must be defined as nullable in the database.
Question 9 of 17 [Entity Inheritance and Object-Relational Mapping]
Which annotation tell the EJB implementation how to join each subclass table record to the corresponding record in its direct superclass table?
Choice 1PKJoinColumn
Choice 2ForeignyKeyJoinColumn
Choice 3FKKeyJoinColumn
Choice 4PrimaryKeyJoinColumn
Question 10 of 17 [Persisting Enums and Collections]
Consider the following code:
public enum CustomerType {INDIVIDUAL, CORPORATE}
public enum OfferPercent {FIFTY, FOURTY }
@Entity public class Customer {
...
public OfferPercent  getOfferPercent () {...}
@Enumerated(STRING)
public CustomerType getCustomerType () {...}
...
}
You want to persist a Customer instance with CustomerType CORPORATE and OfferPercent FOURTY.
What is the value set for CORPORATE, if the customer type property is mapped to a column of integer type, and the offer percent property to a column of varchar type?
Choice 11
Choice 2“CORPORATE”
Choice 30
Question 11 of 17 [Introduction to Querying]
Code :
Query queryCustomersByCountry = entityManager.createQuery("SELECT OBJECT(cust) FROM Customer cust WHERE cust.country = :country");
queryCustomersByCountry.setParameter("country", "Germany");
Which of the following executes this query?
Choice 1Collection customers = queryCustomersByCountry.executeQuery();
Choice 2Customer customer = queryCustomersByCountry.getResultList();
Choice 3Collection customers = queryCustomersByCountry.getResultList();
Question 12 of 17 [Using the Java Persistence API Query Language]
A developer from EPractize Labs Software wants to create a Java Persistence query to fetch Customers for sending Gifts by product ID in where clause. He need to exclude corporate customers from the list.
Corporate product IDs are given below:
13. Skill Evaluation Lab - Academic Edition
14. Skill Evaluation Lab - Corporate Edition
15. SEO Software Submitter Enterprise Edition
16. Email Marketing Software Express Advanced Edition
17. SCEA Part 1 Exam EPractize Labs Enterprise Edition
18. SCEA Part 2 Exam EPractize Labs Enterprise Edition
19. SCJP Exam EPractize Labs Enterprise Edition
Which expression in the query's WHERE clause is correct?
Choice 1WHERE c.productID NOT BETWEEN 12 and 20
Choice 2WHERE c.productID NOT BETWEEN 13 and 20
Choice 3WHERE c.productID NOT BETWEEN 12 and 19
Choice 4WHERE c.productID NOT BETWEEN 13 and 19
Question 13 of 17 [Using the Java Persistence API Criteria API]
Given:
EntityManager em = ...;
String jpql = "select g from Gift where g.itemCount >10";
Query query = em.createQuery(jpql);
List result = query.getResultList();
Select valid CriteriaQuery for the above code
Choice 1 1. EntityManager em = ...
2. CriteriaBuilder qb = em.getCriteriaBuilder();
3. CriteriaQuery<Gift> c = qb.createQuery(Gift.class);
4. Root<Gift> p = c.from(Gift.class);
5. Predicate condition = qb.gt(p.get(Gift_.itemCount), 10);
6. c.where(condition);
7. TypedQuery<Gift> q = em.createQuery(c);
8. List<Gift> result = q.getResultList();
Choice 2 1. EntityManager em = ...
2. CriteriaBuilder qb = em.getCriteriaBuilder();
3. CriteriaQuery c = qb.createQuery();
4. Root p = c.from(Gift.class);
5. Predicate condition = qb.gt(p.get(Gift_.itemCount), 10);
6. c.where(condition);
7. TypedQuery<Gift> q = em.createQuery(c);
8. List<Gift> result = q.getResultList();
Choice 3 1. EntityManager em = ...
2. CriteriaBuilder qb = em.getCriteriaBuilder();
3. CriteriaQuery<Gift> c = qb.createQuery(Gift.class);
4. Root<Gift> p = c.from(Gift.class);
5. Predicate condition = qb.gt(p.get(Gift_.age), 20);
6. c.where(condition);
7. TypedQuery q = em.createQuery(c);
8. List result = q.getResultList();
Question 14 of 17 [Using the Java Persistence API in a Container]
Which is a valid way of injecting a container-managed transaction-scoped persistence context into an EJB 3.0 session bean assuming the application contains only one persistence unit?
Choice 1@PersistenceUnit public EntityManager em;
Choice 2@PersistenceContext private EntityManager em;
Choice 3@TransactionManagement(TransactionManagementType.CONTAlNER) public EntityManager em;
Choice 4@Resource(name="persistence/em", authenticationType=AuthenticationType.CONTAINER) protected EntityManager em;
Question 15 of 17 [Implementing Transactions and Locking]
Which of the following statements are true about JPA locking?
Choice 1JPA 1.0 only supported Optimistic read or Optimistic write locking.
Choice 2JPA 2.0 supports Optimistic and Pessimistic locking
Choice 3Both JPA 1.0 and 2.0 supports Optimistic and Pessimistic locking
Choice 4Both JPA 1.0 and 2.0 supports Optimistic only
Question 16 of 17 [Implementing Transactions and Locking]
Which of the following statements are true about JPA error handling?
Choice 1JPA does not provide a direct way of handling commit failures or error handling.
Choice 2JPA provides direct way of handling commit failures or error handling.
Choice 3When a transaction commit fails, the transaction is automatically rolled back, and the persistence context cleared, and all managed objects detached.
Choice 4If any error occurs in an query before the commit, the transaction will be marked for rollback
Question 17 of 17 [Advanced Java Persistence API Concepts]
Select entity listener life cycle callback method annotations
Choice 1@PrePersist
Choice 2@PostPersist
Choice 3@PostRemove
Choice 4@Post
Choice 5@Persist