Could anyone here tell me in BEA Weblogic8.1, how the Finder methods work in a transaction scope?
1. for a primary key finder
//transaction started p1 = home.findByPrimaryKey(pk); p1.method(); //instance was loaded p2 = home.findByPrimaryKey(pk); //p2 == p1 ? p2.method(); //another instanced loaded?
when the bean reference "p1" was used in a method call after primary key finder was called in a transaction, an instance was loaded, after a while, the primary key finder was called with exactly same primary key again, will the bean reference "p2" it returned equals "p1"? will it load another instance or just use the previously loaded instance?
2. for a non-primary key finder, if the same finder method was invoked twice with same parameter in a transaction, will it return the same collection of references? will it load a seperate collection of instances or use previous collection of instance?
3. for a non-primary key finder, with loads-finder-bean set to true
//transaction started Collection productList1 = home.findByCategory("a"); //iterate through productsList1....
I know when loads-finder-bean set to true, the finder method would always preload the returned collection of instances into cache. will productList2 equals productList1? when the same finder method was called again with same parameter, will the same collection of instances be loaded again or use previously load instances?
will it load another instance or just use the previously loaded instance?
In the EJB 2.0 Specs, Chapter 9 Client View of an Entity, Section 9.8 Primary key and object identity, Page 120, Last Paragraph, it says:
A client can test whether two entity object references refer to the same entity object by using the isIdentical method. Alternatively, if a client obtains two entity object references from the same home, it can determine if they refer to the same entity by comparing their primary keys using the equals method.
So if the entity bean instance is still loaded, calling findByPrimaryKey with the same primary key will not create another instance. It will create only another EJBObject, which references the same entity instance. Because the container uses one instance to represent a particular entity. In this case, you can test if the two EJBObjects refers to the same entity using the way mentioned above.
Share Knowledge to gain it.<br /> <br />SCJP 1.2, SCDJWS 1.4, SCWCD 1.4, SCBCD 1.3, ICAD
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