Session beans that implement the
SessionSynchronization interface (discussed in
Chapter 14) can emulate some of the functionality
of bean-managed entity beans. This approach provides a couple of
advantages. First, these session beans, like entity beans, can
represent entity business concepts; second, dependency on
vendor-specific object-to-relational mapping tools is avoided.
Unfortunately, session beans were not designed to represent data directly in the database, so using them as a replacement for entity beans is problematic. Entity beans fulfill this duty nicely because they are transactional objects. When the attributes of a bean are changed, the changes are reflected in the database automatically in a transactionally safe manner. This is not possible in stateful session beans because, although they are transactionally aware, they are not transactional objects. The difference is subtle but important. Stateful session beans are not shared like entity beans. There is no concurrency control when two clients attempt to access the same bean at the same time. With stateful session beans each client gets its own instance, so many copies of the same session bean representing the same entity data can be in use concurrently. Database isolation can prevent some problems, but the danger of obtaining and using dirty data is high.
Another problem is that session beans emulating entity beans cannot have find methods in their home interfaces. ...