• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

how ejb Finder Methods work in a transacation scope?

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....

Collection productList2 = home.findByCategory("a"); //productList2 == productList1 ?
//iterate through productsList2....

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?
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Robert,

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic