About Question enthuware.oce-ejbd.v6.2.611 :

Moderator: admin

Post Reply
pwang8
Posts: 8
Joined: Thu Apr 09, 2015 12:32 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by pwang8 »

I had that wrong notion for as long as I can remember because we rarely use BMT. Thank you for helping me clear it up.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by himaiMinh »

Hi admin,
I understand why that session bean is a BMT from previous post.
But in the explanation, it says it cannot be a stateless bean as a stateless bean must commit or rollback a transaction before the business / timeout method returns.

But the question does not specify whether m1 or m2 commit or rollback before they return.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by himaiMinh »

Let me rephrase my question:
suppose T1 is the transaction started by a client,
is it possible that m1 commits its own transaction while T1 suspends and m2 commits its own transaction while T1 suspends?
After m1 and m2 commit their own transaction within the methods, T1 resumes.

In this case, the session bean can be either stateless or stateful.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by himaiMinh »

For everyone's reference:
I think the question :
both the methods will be called by the client in the same transaction scope.
is interpreted as m1 and m2 execute in the same transaction started by the session bean.

I think some candidates interpret it as m1 and m2 execute in the same T1, started by the client.

Which interpretation is correct?
1. m1 and m2 execute in the same transaction started by the session bean.
2. m1 and m2 execute in the same T1 started by the client.

I think the interpretation 1) is the correct one. Reasons:
1. user transaction is used in this case.
2. if a bean uses user transaction, this transaction will suspend the client's transaction. The bean will not execute in the transaction started by the client. Therefore, interpretation 2 is not possible.

I hope this analysis is correct and helpful for other people.

aazizi.tarik
Posts: 31
Joined: Sun Dec 27, 2015 1:47 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by aazizi.tarik »

@admin
you said :
Let's say client has transaction T1, it calls method m1 on the BMT bean. In the BMT bean, transaction T1 is suspended. When m1 returns, the client's transaction T1 will resume and the client can call m2 in the same transaction T1. Of course, in m2, T1 will again be suspended, but that is ok.
in that case why it must be a stateful session bean?! it may also be a stateless where the transaction will start and commit at the end! the question dosen't specify anything about that.

I think this question should be reviewed, thanks in advance.

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

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by admin »

Because as per explanation to option 2, it must be a BMT and as per explanation to option 5, a stateless bean has to commit a transaction before it returns, which is not happening here. Therefore, it has to be a stateful session bean.

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

aazizi.tarik
Posts: 31
Joined: Sun Dec 27, 2015 1:47 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by aazizi.tarik »

@admin,

thats the point, you said "which is not happening here."? This is not specified in the question!

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

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by admin »

The question clearly says that the methods are called in the same transaction. That means the transaction is not being committed after the first call. That is why it cannot be a stateless bean. A stateless bean has to commit or rollback the transaction at the end of the call, which is not happening here in this question.
If you like our products and services, please help us by posting your review here.

aazizi.tarik
Posts: 31
Joined: Sun Dec 27, 2015 1:47 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by aazizi.tarik »

Do you mean that this will happen like that (I added what I understood in RED to you answer)
Let's say client has transaction T1, it calls method m1 on the BMT bean. In the BMT bean, transaction T1 is suspended. When m1 returns, the BMT transaction is suspended and the client's transaction T1 will resume and the client can call m2 in the same transaction T1. Of course, in m2, T1 will again be suspended, and the transaction started by the BMT when calling m1 will resume.

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

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by admin »

Yes, as per section 13.6.1:
When a client invokes a business method via one of the enterprise bean’s client views, the container suspends any transaction that may be associated with the client request. If there is a transaction associated with the instance (this would happen if a stateful session bean instance started the transaction in some previous business method), the container associates the method execution with this transaction.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

aazizi.tarik
Posts: 31
Joined: Sun Dec 27, 2015 1:47 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by aazizi.tarik »

Wow! clearly specified int he specs, thx Paul!

henrid
Posts: 31
Joined: Sun Oct 13, 2013 1:20 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by henrid »

Interesting question. So this looks like having nested or overlapping transactions, but of course not active at the same time. Let me take the question a bit further, from what I learned in JPA. If the client is a servlet or other non-EJB, the client's transaction is not suspended, but propagated, even with BMT in the called bean, right? So in this case, all you may have is one BMT transaction from the client? And the callee may even be a stateless bean (if state is not important)? Never mind if this is not okay, but I am just curious.

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

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by admin »

It can't be a stateless bean because as per section 13.3.3 - "Enterprise Beans Using Bean-Managed Transaction Demarcation", "A stateless session bean must either commit or rollback a transaction before it returns. "
Since the problem statement requires that both the methods will be called by the client in the same transaction scope, the bean method cannot commit the transaction.
If you like our products and services, please help us by posting your review here.

henrid
Posts: 31
Joined: Sun Oct 13, 2013 1:20 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.611 :

Post by henrid »

I was talking about a propagated transaction from a non-EJB into an BMT bean, in case when transaction was started before the bean. But never mind.

Post Reply

Who is online

Users browsing this forum: No registered users and 53 guests