aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Doubts -  EJB 3.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Doubts -  EJB 3.0 " Watch "Doubts -  EJB 3.0 " New topic
Author

Doubts - EJB 3.0

Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
I had list of doubts, If some one can clarify them.....

1. What does the name attribute in @Stateles(name="MyTempBean") signify?

2. Explain the following with example:

Dependency injection is performed when the interceptor instance is created, using the naming context of the associated enterprise bean.

3. "If an AroundInvoke method is overridden by another method (regardless of whether that method is itself an AroundInvoke method), it will not be invoked."

Example of this - Why this rule?

4. @PostLoad: Methods marked with this annotation will be invoked after all eagerly fetched fields of your class have been loaded from the datastore. No other persistent fields can be accessed in this method.

Does that mean fields marked for lazy loading cannot be referred to in @PostLoad method?

The @PostLoad method is invoked before a query result is returned or accessed or before an association is traversed.


Before an association is traversed?... what does this mean.

5. ExcludeSuperclassListener would exclude all listeners associated all listeners associated with the superclass and its parent classes?

i.e would it exclude Both listeners defined in
(a) for the immediate parent class and entity callbacks in the immediate parent class.
(a) for all the parent class in hierarchy and entity callbacks in the hierarchy parent class.

->?

6. Timer: Please explain the following:

The Bean Provider must be prepared to handle EXTRANEOUS calls to the timeout callback method in the event that a timer expiration is outstanding when a call to the cancellation method has been made.


Thanks!
Shivani


/** Code speaks louder than words */
Andor Nemeth
Greenhorn

Joined: Jul 06, 2007
Posts: 16
> 1. What does the name attribute in @Stateles(name="MyTempBean") signify?


This is the <ejb-name> element for the bean if you're using an XML deployment descriptor.
Your bean will be registered under the name "MyTempBean" in JNDI, so if you want to do a JNDI lookup, you have to use this name:

Context jndiContext = new InitialContext();
Object ref = jndiContext.lookup("MyTempBean");

2. Explain the following with example:

Dependency injection is performed when the interceptor instance is created, using the naming context of the associated enterprise bean.


Interceptor objects are tied to enterprise beans they intercept.
Every enterprise bean has its OWN naming context (think of it as own JNDI registry).
Consider an interceptor as an extension to the EJB's bean instance! Interceptors are created along with bean instances. They are created, passivated, activated, destroyed with the bean instanced they belong to.

So: as interceptors have the same access to the same naming context as the beans they belong to, dependency injection will be based also on this shared naming context. (Naming context shared among the bean and it's interceptors.)

3. "If an AroundInvoke method is overridden by another method (regardless of whether that method is itself an AroundInvoke method), it will not be invoked."

Example of this - Why this rule?


Lets suppose we have two interceptor classes (a class with an @AroundInvoke method:

public class Interceptor1 {
@AroundInvoke
private Object doMyInterception(InvocationContext ic) throws Exception { //do something... }
}

public class Interceptor2 extends Interceptor1 {
@AroundInvoke
private Object doMyInterception(InvocationContext ic) throws Exception { //do someting else... }
}

In this case if we use Interceptor2 to intercept a bean, Interceptor1's doMyInterception method won't be called! It's like the normal Java override!

The second case:
Interceptor1 class is the same as above.
We change Interceptor2 a little bit:

public class Interceptor2 extends Interceptor1 {
//Overriding without annotating with @AroundInvoke
private Object doMyInterception(InvocationContext ic) throws Exception { //do someting in this regular method... }

@AroundInvoke
private Object myNewInterceptorMethod(InvocationContext ic) throws Exception { //do interception... }

} //Interceptor2

If Interceptor2 is used with an EJB, the overridden doMyInterception in Interceptor1 won't be called. myNewInterceptorMethod in Interceptor2 will be called. (Because it has been annotated with @AroundInvoke!)

Conclusion: just follow the regular Java overriding rules whether your method is annotated with @AroundInvoke!


4. @PostLoad: Methods marked with this annotation will be invoked after all eagerly fetched fields of your class have been loaded from the datastore. No other persistent fields can be accessed in this method.

Does that mean fields marked for lazy loading cannot be referred to in @PostLoad method?


I think the same as you...
People! Somebody else? ;-)


I hope i've helped.
Greetings,
Andor


Originally posted by Shivani Chandna:
I had list of doubts, If some one can clarify them.....

1. What does the name attribute in @Stateles(name="MyTempBean") signify?

2. Explain the following with example:

Dependency injection is performed when the interceptor instance is created, using the naming context of the associated enterprise bean.

3. "If an AroundInvoke method is overridden by another method (regardless of whether that method is itself an AroundInvoke method), it will not be invoked."

Example of this - Why this rule?

4. @PostLoad: Methods marked with this annotation will be invoked after all eagerly fetched fields of your class have been loaded from the datastore. No other persistent fields can be accessed in this method.

Does that mean fields marked for lazy loading cannot be referred to in @PostLoad method?



Thanks!
Shivani


SCJP 5<br />SCBCD 5 (next target)
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
Hello Andor,

Thanks for replying detail to each of my queries...!

What abt the last question on Timer?

Regards,
Shivani.
[ July 26, 2007: Message edited by: Shivani Chandna ]
Andor Nemeth
Greenhorn

Joined: Jul 06, 2007
Posts: 16
The container interleaves calls to the timeout callback method with the calls to the business methods and the life cycle callback methods of the bean. The time at which the timeout callback method is called may therefore not correspond exactly to the time specified at timer creation. If multiple timers have been created for a bean and will expire at approximately the same times, the Bean Provider must be prepared to handle timeout callbacks that are OUT OF SEQUENCE. The Bean Provider must be prepared to handle EXTRANEOUS calls to the timeout callback method in the event that a timer expiration is outstanding when a call to the cancellation method has been made.


I have been thinking about this text, but I'm not quite sure if I understand it. I suppose, I don't
The last sentence makes me a bit crazy!

May be some native English speaker with SCBCD ambitions could help!
Somebody!?

Greetings,
Andor
[ July 26, 2007: Message edited by: Andor Nemeth ]
Tony McClay
Ranch Hand

Joined: May 22, 2003
Posts: 33
Originally posted by Andor Nemeth:
The container interleaves calls to the timeout callback method with the calls to the business methods and the life cycle callback methods of the bean. The time at which the timeout callback method is called may therefore not correspond exactly to the time specified at timer creation. If multiple timers have been created for a bean and will expire at approximately the same times, the Bean Provider must be prepared to handle timeout callbacks that are OUT OF SEQUENCE. The Bean Provider must be prepared to handle EXTRANEOUS calls to the timeout callback method in the event that a timer expiration is outstanding when a call to the cancellation method has been made.


I have been thinking about this text, but I'm not quite sure if I understand it. I suppose, I don't
The last sentence makes me a bit crazy!

May be some native English speaker with SCBCD ambitions could help!
Somebody!?

Greetings,
Andor

[ July 26, 2007: Message edited by: Andor Nemeth ]


Tony McClay<br />Architect / Developer, SOA and Jave Enterprise Edition 1-5<br />---------------------------------------------------------------------- <br />Sun Certified Enterprise Architect, Enterprise Edition 5 (Step 1 of 3)<br />Sun Certified Web Component Developer, Enterprise Edition 4<br />Sun Certified Business Component Developer Enterprise Edition 5<br />Sun Certified Programmer , Standard Edition 5.0
Tony McClay
Ranch Hand

Joined: May 22, 2003
Posts: 33
This appears to be a general statement that is made to place no responsibly on the specification for the container to handling Timer Cancellations after the process of the Timer trigger has started.


I would have to look at each App Server's code to see how they implemented callbacks / Timer Triggers to tell their direct behavior. It is even hard to envision how a situation like this could occur, but we are developers and someone will eventually fall into this hole eventually.

What hole?

Speculatively : Multiple Timers are set to Expire on a Stateless Session bean, and the container maintains timers in an external source to the bean and the bean throws a System Exception, the bean is in the process of being removed while another Timer is Triggered, and the container doesn't create more stateless session beans to accept the trigger?

or

Speculatively : Another class has the TimerHandle to Timer, gets the Timer Object and calls cancel(), while the timer has triggered and the code is in an Interceptor class/method?

OK, maybe I should log off for the day. But basically this is an abnormal situation. I would be curious to see a real world situation where this applies...

Tony



6. Timer: Please explain the following:

quote:The Bean Provider must be prepared to handle EXTRANEOUS calls to the timeout callback method in the event that a timer expiration is outstanding when a call to the cancellation method has been made.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubts - EJB 3.0