126 Chapter (Web design rates) 6 Entity Bean Instances Are a
126 Chapter 6 Entity Bean Instances Are a View into a Database When you load entity bean data into an in-memory entity bean instance, you read in the data stored in a database so that you can manipulate the data within a Java Virtual Machine. However, you should think of the in-memory object and the database itself as one and the same. This means if you update the in-memory entity bean instance, the database should automatically be updated as well. You should not think of the entity bean as a separate version of the data in the database. The in-memory entity bean is simply a view or lens into the database. Of course, in reality there are multiple physical copies of the same data: the in-memory entity bean instance and the entity bean data itself stored in the database. Therefore, there must be a mechanism to transfer information back and forth between the Java object and the database. This data transfer is accomplished with two special methods that your entity bean class must implement, called ejbLoad() and ejbStore(). ejbLoad() reads the data in from the persistent storage into the entity bean s in-memory fields. ejbStore() saves your bean instance s current fields to the underlying data storage. It is the complement of ejbLoad(). So who decides when to transfer data back and forth between the in-memory bean and the database? That is, who calls ejbLoad() and ejbStore()? The answer is your EJB container. ejbLoad() and ejbStore() are callback methods that the container invokes. They are management methods required by EJB. The container worries about the proper time to call ejbLoad() and ejbStore() this is one of the value-adds of the container. This is shown in Figure 6.3. Your beans should be prepared to accept an ejbLoad() or ejbStore() call at almost any time (but not during a business method). The container automatically figures out when each of your instances needs to be refreshed depending on the current transactional state (see Chapter 12). This means that you never explicitly call your own ejbLoad() or ejbStore() methods. This is one of the advantages of EJB: You don t have to worry about synchronizing your objects with the underlying database. The EJB black box handles it for you. That is why you can think of the entity bean and the database as the same; there should never be a time when the two are transactionally out of sync.
Do you have a godaddy domain name? If you do, you have found the right web hosting provider for you.Our Godaddy Web Hosting packages are the best match to well known, affordable godaddy domain names.