About Question enthuware.oce-jpad.v6.2.594 :

Moderator: admin

Post Reply
jszczepankiewicz

About Question enthuware.oce-jpad.v6.2.594 :

Post by jszczepankiewicz »

In my opinion this answer is wrong. The correct one is:
"Container managed, transaction scoped EntityManager"

not:
"Container managed, transaction or extended scoped EntityManager"

Why:
It is stated that the injected object is EntityManager, NOT EntityManagerFactory. If container injects EntityManager in Servlet or SLSB it injects Transaction Scoped Persistence Context (most containers probably throws exception or injects null if @PersistenceContext(type=PersistenceContextType.EXTENDED) requsted in something other than SFSB. Because injection of EntityManager with declaration of Extended persistence context only works in SFSB. If the question will suggest that there will be injection of EntityManagerFactory - the servlet might use the creation of EntityManager in Application style:
EntityManager em = EntityManagerFactory.createEntityManager() which will return extended scoped entity manager.
thus the actual answer might be true, but will require restructuring the question.

The injection:
"@PersistenceContext(type=PersistenceContextType.EXTENDED|TRANSACTION)
EntityManager orderEM;"
only works in SFSB.

admin
Site Admin
Posts: 10074
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.594 :

Post by admin »

The question says, "...into your components such as a servlet or a session bean", which means it is only trying to explain what it means by component and that it is not specifying the type of the component. Since the question does not specify the type of session bean, it can be assumed that it could be SLSB or SFSB. Therefore, depending on the type of the bean the transaction type could be of any type.

Had the question specified the exact type of the component, the answer might be different. As of now, it is a generic question and the answer is generic as well. The following statement from the specification is also of the similar nature. It does not talk about the exact component either.
7.2.1 Obtaining an Entity Manager in the Java EE Environment
A container-managed entity manager is obtained by the application through dependency injection or
through direct lookup of the entity manager in the JNDI namespace. The container manages the persistence context lifecycle and the creation and the closing of the entity manager instance transparently to the application.
The PersistenceContext annotation is used for entity manager injection. The type element specifies whether a transaction-scoped or extended persistence context is to be used, as described in section 7.6.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

jszczepankiewicz

Re: About Question enthuware.oce-jpad.v6.2.594 :

Post by jszczepankiewicz »

Sorry but you constructucted wrong question in my opinion. The question is straightforward:"What persistence type can be selected if injecting EntityManager in Servlet". The answer is ONLY
"Container managed, transaction scoped EntityManager". You can not inject Extended type EntityManager in Servlet - the answer is currently wrong. Quoted specification does not specify kind of object, but your question does and thus does NOT have same meaning. If someone will learn this question and sees on the exam question:

What persistence type can be selected if injecting EntityManager in Servlet

will answer WRONG using your question & answer.

admin
Site Admin
Posts: 10074
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.594 :

Post by admin »

jszczepankiewicz wrote:The question is straightforward:"What persistence type can be selected if injecting EntityManager in Servlet".
Hi,
Thank you for clarifying. I think I see where the confusion is. In your version of the question, you are asking about a specific component i.e. a servlet and in that case I agree what you are saying.

But what you've written is not what the question asks. The exact question statement is as follows-
What type of EntityManager do you get when a Java EE compliant container injects an EntityManager into your component such as a Servlet or a Session bean?
The question is very generic. It says the component can be a servlet or a session bean. In that case, depending on what it is, the entity manager could be of either type.

However, since it is causing a confusion and so it should be changed to avoid it anyway.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests