Consider a bean having a number of finder methods and a number of get and set methods. Consider a situation where a client (Client_1) executes a finder method which returns say 100 records. The client scrolls through all these records, so 100 bean instances would be created and assigned to the corressponding EJBObjects (I suppose). Now a second client (Client_2) executes some other finder method which also returns 100 records, 50 of which are common to the one fetched by Client_1. My question is: 1) Would 100 bean instances be created for Client_2 also (I don't think so) or 2) Only 50 instances for the non-common records be created, while Client_2 would be assigned the same references for the 50 common records. If not so, then what if Client_1 executes a set method on one of the common records. How would the EJB Container synchronize this?
I think you're closer to reality with number 2. For an entity bean object, there will be zero or one instance in the container at any given time. E.G., use find method to select person entity bean that has a fingerPrint == Blob. Assuming no poor workpersonship, there will be only one bean with that key. It could be in the container, in the datastore, or is could be non-existant. Your example is not true for stateful and stateless beans.
Ans is 2 but here is some food for thought - Lets say we have an Entity bean that has name as one of the attributes and a finder method is there that finds all the beans that have "name" starting with "particular alphabet" lets say "A". Lets say the query was fired by two clients and the result set included three beans : name=Alice name=Alison name=Alisa Now one of the client called the set method and changed the third bean to name=Kalisa So now the PK is still the same and the second client which is printing out the query results to a brower UI will give out incorrect info which may prompt the user of the application to open up a bug ticket: User asked for name starting with "A" and he/she recvd: name=Alice name=Alison name=Kalisa
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop