• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Bean things in afterCompletion()

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In HFEJB page 512 bottom right box we are told that we cannot access a resource factory or other bean in this method. Yet the spec tells us:

Accessing resource managers and enterprise beans is disallowed in the session bean methods for which the Container does not have a meaningful transaction context or client security context.



Since we have a client security context we should be able to access these resources.

regards,
Simon
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a stateful session bean which implements the javax.ejb.SessionSynchronization interface runs, it does so in a transaction (because the Application Assembler has specified the transaction attribute of Required, RequiresNew or Mandatory). The transaction completes just after the beforeCompletion() method ends. The afterCompletion() method now runs, and the Container no longer has a meaningful transaction context. Therefore, accessing resource managers and enterprise beans is disallowed.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roger,

Do you remember our earlier discussion about this. We concluded that Session beans could access resource managers and other beans in their ejbCreate methods because, although the method was not in a transaction, the method had a client security context and that either of these conditions was sufficient to provide access. So, since the afterCompletion method has a client security context, but is not in a transaction, it should allow access to the resources. There is definately a contradiction somewhere!

regards
Simon
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are still getting tripped up with OR conditions. Think of this an a conditional operator:


if (boolean expression 1 || boolean expression 2)


If boolean expression 1 evaluates to true, then boolean expression 2 is not evaluated.

Accessing resource managers and enterprise beans is disallowed in the session bean methods for which the Container does not have a meaningful transaction context or client security context.


If the expression (Container does not have a meaningful transaction context) is true, then accessing resource managers and enterprise beans is disallowed in the session bean methods.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roger, you can't have it both ways! Look at page 196 in HFEJB. A stateful session bean in the ejbCreate method does not have a transaction context, but does have a security context AND IS able to access the resources. This case is identical to the example on page 512, in which the afterCompletion method is not in a transaction but has a security context but this time IS NOT able to access the resources.

This is a contadiction.

We have been arguing the meaning of the following rather confusing statement (with all its negatives).

Accessing resource managers and enterprise beans is disallowed in the session bean methods for which the Container does <b>not</b> have a meaningful transaction context or client security context.



You seem to be saying the following:

Access tx sec
0 0 0
0 0 1
0 1 0
1 1 1

A 0 in the access column means access is denied.

I am saying the following:

Access tx sec
0 0 0
1 0 1
1 1 0
1 1 1

In my opinion the much quoted statement from the spec simply expresses the first line in both our tables. There now remains the issue of which table truly expresses EJB and then we still have the contradiction to both our tables! Any thoughts on this would be much appreciated.

regards
Simon

[ May 25, 2004: Message edited by: Simon Ingram ]

[ May 25, 2004: Message edited by: Simon Ingram ]
[ May 25, 2004: Message edited by: Simon Ingram ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simon,

You are getting into a fearful muddle over this.

From the afterCompletion() method, you have no access to resource manager or EJB. Why? Because the Container either does not have a meaningful transaction context (which is applicable here because the transaction has completed) or client security context. Only one condition has to be true for access to be denied.

Why is this difficult to understand?
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because, my dear and patient friend, if access is denied because we do not have either a tx context or a security context, then access should be denied for stateful session beans in ejbCreate and ejbRemove (it isn't - see page 196 HFEJB).

Simon
 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I always thought limiting afterCompletion's access was sort of dumb anyway. After afterCompletion runs, it ends in a state where the next method CAN access other beans, and resources, right? So why take it away from the afterCompletion method, then give it back to whatever method happens to run next?

--Dale--
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, I think there is an error in the spec! The way I look at it, for stateful session beans the ejbCreate(), ejbRemove(), ejbActivate(), ejbPassivate() and afterCompletion() methods are all the same. By this, I mean that they all execute with an unspecified transaction context but with a client security context. Therefore, resource manager access and enterprise bean access must be disallowed (as the spec shows for afterCompletion()).

There is another possibility: that access is allowable for the ejbCreate(), ejbRemove(), ejbActivate() and ejbPassivate() methods, but the spec should say something like this:

Accessing resource managers and enterprise beans is allowed in the session bean methods for which the Container does have a meaningful transaction context or client security context.



What the spec says (see below) looks like a copy and paste, and we all know what sort of bugs this can create :

Accessing resource managers and enterprise beans is disallowed in the session bean methods for which the Container does not have a meaningful transaction context or client security context.

 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I always thought limiting afterCompletion's access was sort of dumb anyway. After afterCompletion runs, it ends in a state where the next method CAN access other beans, and resources, right? So why take it away from the afterCompletion method, then give it back to whatever method happens to run next?


Being a bit frivolous ... This just sprung to mind and it dates me horridly.

"It's a new dawn" from Jefferson Airplane at Woodstock.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roger,

your reply is a big relief to me. I was beginning to feel I was going mad! Or as you put it, getting into a fearful muddle. I agree with you that the wording in the spec is confusing and our problem is resolved with the alternate version you suggest. It would be nice to know what the moderators think!

Simon
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This discussion is really interesting and it would lead the EJB aspirants to find the real correct meaning of the words in the spec... The thing is that we don't know what to answer in the exam... Since we are in the same boat to SCBCD goal, we should conclude one and only thing here...

As a conclusion, accessing other resources and EJBs from afterCompletion() is disallowed as well as from ejbCreate()...

or

As a conclusion, accessing other resources and EJBs from afterCompletion() is allowed as well as from ejbCreate()...

Select one so that we don't have to waste our time thinking about it in the exam room....
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right, Ko Ko. It would be nice if one of the moderators were to give us a definitive answer. Unfortunately, I think they are leaving it to Roger to answer everyone's questions! So far he is doing such a fine job that they have probably taken a snap holiday and are even now sunning themselves on a distant beach. As for the exam, best to toss a coin!
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, as far as the exam is concerned, you know which answer is the right one - even if you think it is wrong!

We haven't seen much of Kathy, she is I believe working hard on her new Head First SCWCD book which she wants to release whilst at JavaOne next month.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Roger Chung-Wee:
Guys, as far as the exam is concerned, you know which answer is the right one - even if you think it is wrong!

We haven't seen much of Kathy, she is I believe working hard on her new Head First SCWCD book which she wants to release whilst at JavaOne next month.



Yes, Roger is right. I used to see Kathy's replies in the past everyday. But these days, she seems to be really busy with the upcoming book... So Roger is the one, who is roaming around this forum as he also has his SCBCD exam on 1st June, Mine on 30th May... So let's help each other and beat it!!!
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roger, even the following statement doesn't help:

Accessing resource managers and enterprise beans is allowed in the session bean methods for which the Container does have a meaningful transaction context or client security context.



afterCompletion(boolean committed) does have client security context, but it can't still access resource managers and enterprise beans

[ June 18, 2004: Message edited by: mini mehta ]


[ June 18, 2004: Message edited by: mini mehta ]
 
What's wrong? Where are you going? Stop! Read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic