posted 17 years ago
1. The ejbCreate() method doesn't run in a valid transactional context. The spec doesn't do much to explain why not, except to say that it would unnecessarily complicate the life cycle of the stateful session bean. I'm willing to accept this explanation. Unlike an entity bean, which usually has to write an entry to a database as part of its create process, a stateful session bean just needs to populate its state variables. It might need to read data from a database, either directly or through other beans, but it would never need to alter any data during the creation process. If it doesn't alter data, then it doesn't need a transaction.
2. setSessionContext(), and all the other setXxxxContext() methods, are just part of the setup process for the bean. They can be used to store values and references to objects that will be used later, but shouldn't be used to do any real work. Usually they are just used to store a reference to the context in the bean instance for later use. However, you could also store a reference to the Home interface, or set up the values and object references configured in the bean's environment. You can't actually use these object references until later in the life cycle, but at least you can get them ready.