Hi Hui,
Am i right to say that any changes made to entity beans is immediately synchronized with the database?
Yes and no. No because they are not committed immediately and yes because you�ll always get the latest data (supposing you�re using the right transaction isolation level). Actually it works like this: the container calls the ejbLoad when the transaction starts and it calls ejbStore before committing the transaction. A very simple approache to keep the data in sync, isn�t it? The story could become little bit more complex though, because the container might have special features (that could be turned on and off) to allow caching the data between transactions. If that�s the case, the container will reduce the number of ejbLoad/ejbStore for improving performances.
Hi Mithal,
I hope you won�t mind if I�ll make some comments on your remark; this might help Hui to understand the complexity of this issue.
Entity bean is a good choice when you need to update a few rows in the db often, but not a good choice for query/search. You should be using JDBC for Reading. However, in your case with a million users, it makes no sense to retrieve their list. Entity beans are not suitable for OLAP data retrieval and you shud use the db vendor specific tool for this.
It�s true that inside the J2EE community there is a very strong feeling that entity ejb are a very cumbersome solution, which is a too complex issue to discus it here. There is also the other side of the barrier that says: it might be possible to build a good J2EE system using entity ejb. However this requires a very in-depth knowledge of the container and one will mostly end up implementing vendor specific solutions, which will break the J2EE essential promise "build once run everywhere". Only applying general J2EE knowledge might not be enough. To make long story short, I implemented once a solution like this, using read only entity beans for caching the data in order to provide fast access to a mission critical application; it worked just fine. I cached about several hundred thousand entity ejbs, which represented account structures and they were very large (more than 100 attributes each) data structures. The container behaved great and didn�t even seem to bother about the data it needed to cache. I guess the ultimate choice is whether to play safely, using JDBC for reading or to accept the challenge and assuming the risk of going with vendor specific ejb solutions.
Regards.