Search your topic in Java2share
Home > SCBCD > SCBCD Question Bank
eXTReMe Tracker

6. Java Persistence Entity Operations (SCBCD)

Q: 01 Which statement about entity manager is true?
A. A container-managed entity manager must be a JTA entity manager.
B. An entity manager injected into session beans can use either JTA or resource-local transaction control.
C. An entity manager created by calling the EntityManagerFactory.createEntityManager method always uses
JTA transaction control.
D. An entity manager obtained through resource injection in a stateful session bean can use a resource-local
EntityTransaction for transaction control.

Answer: A

 Q: 02 A developer is modifying an existing Java EE application that uses the JDBC
API to access a database. This code must be used but cannot be changed, and new code needs to be added
that uses the Java Persistence API.
Both parts of the code will execute in the same JTA transaction.
Which method of the EntityManager interface should the new code use to ensure that the data read by
JDBC statements includes the state of managed entities?

A. Call refresh on each changed entity.
B. Call flush at the end of each business method.
C. Call find before accessing any managed entity.
D. Call lock at the beginning of each business method.

Answer: B

Q: 03 A developer writes an interceptor class called FooInterceptor containing the
following AroundInvoke method:
11. @AroundInvoke
12. public Object intercept(InvocationContext ctx) {
13. return "intercepted";
14. }
FooInterceptor is applied to a business method in a stateless session bean:
11. @Interceptors(FooInterceptor.class)
12. public String testzero(int i) {
13. return (i == 0) ? "zero" : "not zero";
14. }
Which describes the result when a client invokes the testzero method with a value of 1?

A. The intercept method is NEVER invoked.
B. The client receives a return value of "zero".
C. The client receives a return value of "not zero".
D. The client receives a return value of "intercepted".

Answer: D

Q: 04 The Java Persistent API defines certain rules for persistent entities. These
rules are required by the persistent provider to manage entities at runtime. Which statement is correct,
assuming NO mapping descriptor is used?

A. Entities must extend a persistent base class.
B. Entities must implement the interface PersistentEntity to be managed by the persistent provider.
C. A field without a transient modifier must be annotated as @Persistent to be stored in the database.
D. A field without a transient modifier must be annotated as @Transient to NOT be stored in the database.

Answer: D