This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Please help me to clear my doubts... I have few questions here... 1. Why should we use Entity Bean? 2. I have to make sql join queries more frequently in my application, does the enity beans support joing queries? 3. Inorder to imporove the performance of Application server the entity beans must be destroyed if they are not in use, how can i destroy entity beans? I don't understand when entity beans gets destroyed? 4. Does Entity Beans supports Data Cache? 5. How Entity Beans are benificial over Stateless and State-full Session Beans? Thanks in advance, Mahesh
Entity beans are probably one of the most controversial technologies within J2EE and is a fairly large and complex topic. To summarise some answers for your questions... (1) Entity beans are generally used to represent persistent information - for example customers within your application. (2) Yes, since EJB 2.0, entity beans support the notion of Container Managed Relationships (CMR) meaning that you can declaritively define relationships between your entity beans. Of course, you can still program these relationships yourself if required. (3) In terms of entity beans being destroyed to aid performance, this isn't strictly true. In fact, the Java objects representing entity beans can be passivated by the container when they have not been accessed for a specific time. This enables the container to free up resources. Subsequent requests for those entity beans result in the activation of those passivated instances. (4) Most application servers support some degree of data caching. When you introduce clusters into the equation, the issues around data caching become much more complex through aspects such as distributed locking and ensuring the caches are kept up to date. (5) Entity beans are another tool in your toolbox and provide a very easy framework/architecture with which to build the persistent objects that are a part of your application. Stateful and stateless session beans are generally used to represent business processes, and therefore compliment entity beans rather well. Hope these (rather simplified) answers help. Simon
Here is a link to a similiar topic from a while back: Best design practices. Let me start by saying that I am not a very big fan of Entity Beans. However, like many other things, Entity Beans definitely have a place. If you are looking for a persistance engine then I think CMP 2.0 is pretty good. It definitely still has many limitations, but right now CMP is the only well supported standards-based persistance engine. This could very well change in the future with the growing popularity of technologies such JDO. My view is, if you want free persistance and you are willing to deal with some of CMP's limitations, then Entity Beans are a fair choice. However, if persistance is not a big concern and you are looking to take advantage of the other benefits of EJB, then I would say you should skip Enity Beans completely. JDO or POJO wrapped with Session Beans would be a much better solution in this case.