File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes EJBObject, EJBHome and SessionBean methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJBObject, EJBHome and SessionBean methods" Watch "EJBObject, EJBHome and SessionBean methods" New topic

EJBObject, EJBHome and SessionBean methods

Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209
I am currently preparing for SCBCD exam. I use "Head First EJB" as a text book and JBoss as an application server. I'd appreciate if you could shed some light on the following issues:
1. The ejb spec says that stateful sb home and the actual bean must have at least one create method and must start with string "create" in home and "ejbCreate".
I have created a stateful sb that has one create method:
a) createMe( String ) in home interface
b) ejbCreateMe ( String ) in the actual bean.
When I try to deploy such bean JBoss throws a deployment exception:
[org.jboss.ejb.EJBDeployer.verifier] EJB spec violation:
Bean : IAmStateful
Section: 6.10.6
Warning: A session bean's home interface must define one or more create(...) methods.
Does it mean that there should be always at least one create method called exactly "create" and "ejbCreate" respectively in home / bean?

2) Why does the ejb spec say that EJBObject can accessed from ejbCreate method of the stateless sb? Stateless sb creation is not linked to the client at all. So what EJBObject are we accessing from ejbCreate? It cannot be EJBObject that is serving the client, can it be?

3) Also I have tried to get EJBObject while in session bean's setSessionContext( SessionContext ) method expecting some sort of error. However, to my surprise there was no error and I could even execute getHandle() on EJBObject!?!? The spec says that EJBObject cannot be accessed from within setSessionContext ( SessionContext ). So what is happening then?
4) In addition, the spec says that EJBObject#getPrimaryKey() can only be called on EntityBeans, or RemoteException is thrown. However, I've got the client that calls getPrimaryKey() on biz interface ( i.e. stub to EJBObject ) and... instead of throwing ex it returns a value that happens to be jndi name ( name used to find session bean's home interface in directory tree ). Is it an expected behaviour?

I greatly appreciate your answers.
Thanks a lot.

Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

Many app servers don't implement the spec to the letter. For example, all of the app servers that I have used want the methods to be create() and ejbCreate() rather than just start with it.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209
Thanks a lot, Jeanne. Now it is clear to me why some things in Jboss do not work as defined in the spec.
I still can't get what EJBObject are given access to when in ejbCreate(...) method of stateless sb? Stateless sb is not linked to the client's call to create(...) on home interface. In theory, container creates stateless bean when there is no EJBObject( client ) to associate with the bean.
I agree. Here's the link:
subject: EJBObject, EJBHome and SessionBean methods
jQuery in Action, 3rd edition