This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJBObject, EJBHome and SessionBean methods

 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex,
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.
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic