First page Back Continue Last page Graphics
Load & Store
EntityBean has
two unique life
cycle methods:
- Use to relate to other beans
- Use to synchronize with additional state data
- Empty in simple CMP beans
ejbLoad( )
- Called just after container
loads bean's state
When does the container call these methods?
- Depends on transactions. More later...
See example in notes...
- A CustomerBean that stores customer’s full name
Notes:
The EntityBean interface has two methods that SessionBean lacks, because they pertain to persistence. ejbLoad( ) is called just after the container loads the bean's state from the database. ejbStore( ) is called just before the container saves the bean's state.
The bean class would use these methods to synchronize additional state data such as calculated fields or related data. Most container-managed persistence beans will leave these methods empty. But if certain data is held in a different format in the database than in the bean instance, these two methods can be used to convert back and forth.
These methods will be empty in most CMP beans. But the following example shows a possible use for them in the CMP CustomerBean class: to store the full name in a String variable and return its value from getFullName( ) rather than call getFirstName( ) and getLastName( ) every time.
The class has a private instance variable for the full name.
The variable is updated whenever new data is loaded from or written to the database.
See the code on the next page...