exam questions

Exam 1z0-895 All Questions

View all questions & answers for the 1z0-895 exam

Exam 1z0-895 topic 1 question 82 discussion

Actual exam question from Oracle's 1z0-895
Question #: 82
Topic #: 1
[All 1z0-895 Questions]

A developer implements a CMT session bean with a method storeBoth which inserts data both a related database and an LDAP server. The relational database supports transactions while the LDAP system does NOT.
Given that both updates should succeed or be rolled back, while is the best solution?

  • A. Implement the SessionSynchoronization interface in the session bean. In the afterCompleteion method, the LDAP inserts are rolled back if false is passed as an argument to the afterCompletion method.
  • B. Define the transaction attribute of the method storeBoth as REQUIRED. The container manages the transactions and will roll back modifications if something goes wrong in either database insert or LDAP insert.
  • C. Define the transaction attribute of the method storeBoth as REQUIRED_NEW. Carry out the database insert first. Subsequently, execute the LDAP inserts, catching LDAP exceptions. If exceptions are raised, call the SessionContext.setRollBackOnly method.
  • D. Define the transaction attribute of the method storeBoth as REQUIRED_NEW. Carry out the LDAP insert first. If SessionContext.getRollBackOnly returns false, execute the database inserts, catching SQL exceptions. If exceptions are raised, call the SessionContext.setRollBackOnly.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️
The method should start a new transaction, so we use the REQUIRED_NEW attribute.
For the LDAP operation we can only detect LDAP exceptions. We cannot check the status of the LDAP operation through SessionContext.getRollBackOnly.
Note:
* CMT - Container-Managed Transactions
* RequiresNew Attribute
If the client is running within a transaction and invokes the enterprise beans method, the container takes the following steps:
Suspends the clients transaction

Starts a new transaction -
Delegates the call to the method
Resumes the clients transaction after the method completes
If the client is not associated with a transaction, the container starts a new transaction before running the method.
You should use the RequiresNew attribute when you want to ensure that the method always runs within a new transaction.
Reference: The Java EE 5 Tutorial, Container-Managed Transactions

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Currently there are no comments in this discussion, be the first to comment!
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...