SCBCD Guide
HomeSCJP | SCWCD | SCBCD | SCEA | SCSA

--------------------------------------------------
ENTITY BEANS
--------------------------------------------------

1. the persistent state of the instance at the beginning of the ejbRemove() method
is the same as it would be at the beginning of a business method. The container must
invoke ejbLoad before it invokes ejbRemove().

2. Entity beans should be in the same local scope if they have a relationship.

3. The bean proider can manipulate the relationships at runtime via get and set accessor method.

4. For ejbSelect method, the container should make sure that no duplicates are returned.

5. Invoking javax.ejb.EJBContext.getUserTransaction() in an entity bean instance method results in
java.lang.IllegalStateException because entity beans must always use container-managed transactions.

6. In ejbActivate, initialize transient fields. Since the transient fields are not preserved while serialization-
deserialization process, you need initialize such fields to appropriate values in ejbActivate() method

7. Customer 0..1 ----------- 0..* Address
What will be the result of the follow method call made by a client?
somecustomer.setAddresses(null);

This call is illegal. It should pass an empty Collection object if it wants to remove all the addresses for a
customer.

8. With container-managed persistence, the container performs the database insert after the ejbCreate(...) method
completes (anytime after this).

9. The Container must establish the primary key before it invokes the ejbPostCreate(...) method.

10. The container synchronizes the instance’s state before it invokes the ejbRemove method. This means
that the state of the instance variables at the beginning of the ejbRemove method is the same as it
would be at the beginning of a business method.

ejbActivate()/ejbLoad is called prior to calling ejbRemove().

To synchronize instance's state, call ejbLoad().
To synchronize entity object's state in db, call ejbStore().

11. Valid types of persistent CMP fields of a 2.0 CMP entity bean
A primitive type.
All serializable types

12. Caller of the finder method must always be prepared for FinderException.

13. The lack of a local interface prevents other entity beans from having a relationship
to it.

14. The abstract-schema defines the bean's persistent fields and relationships.
It is used ONLY with CMP.

15. All static fields in the bean should be marked FINAL.

16. CMR can only exists among entity beans with the same LOCAL RELATIONSHIP SCOPE

17. For ejbSelect method, the container should ensure that NO DUPLICATES are returned.

19. Multi-object finders:-
The collection of values returned by the Container may contain duplicates if DISTINCT is not specified
in the SELECT clause of the query for the finder method.
A client program must use the PortableRemoteObject.narrow(...) method to convert the
objects contained in the collections returned by a finder method on the entity bean’s remote home interface
to the entity bean’s remote interface type.

20. Return Types:-
finder methods :- EJBObjects or EJBLocalObjects of the same type as the entity bean (or collection of it)
select methods :- EJBObjects, EJBLocalObjects, or cmp-field types (or collection of it),
or cmr-field types (or collection of it).


21. If a single object return finder/select method returns more than one values, then it should throw a
FinderException.

22. <cascade-delete>
The cascade-delete element can only be specified for an ejb-relationship-role element contained in an
ejb-relation element if the other ejb-relationship-role element in the same ejb-relation element
specifies a multiplicity of One. The cascade-delete option cannot be specified for a many-to-many relationship.

23. The ejbSelect method MUST define javax.ejb.FinderException.

24. Home methods cannot be declared static.. ( ie it can be declared final)
Select methods can be declared static and final. (well, this is abstract by default)
create method/business method cannot be declared final OR static

25. The Container MUST establish the primary key BEFORE it invokes the ejbPostCreate<METHOD>(...) method.

26. The instance is in the READY STATE when ejbRemove() is invoked and it will be entered into the POOL
when the method completes.
The container synchronizes the instance’s state before it invokes the ejbRemove method

27. For CMP, no need to define a default constructor. A default one will be provided.

28. ejbLoad(), ejbStore() and business methods can be called in ANY order.

29. Container needs to call ejbActivate(), ejbLoad() before it can call a ejbRemove().

30. ejbLoad(), ejbRemove(), ejbSelect() --> runs in the tx context of the method that causes it's invocation.

31. <res-sharing-scope>shareable</..>
Other beans in the same app using the same resource, in the same tx can share.

32. If entity beans uses UserTx methods, a javax.naming.NameNotFoundException will be thrown ????????????????

33. Create methods can be OVERLOADED

34. BEWARE OF the word "EXISTING OBJECT" and "NEW OBJECT".