> imagine, I have a table Foo with two rows, both Integers X and Y on my
> relational database.
>
> table Foo (X is the primary key!) with example data
X should be unique if it is to serve as a primary key.
> X Y
> 1 2
> 1 3
> 2 3
> 2 4
>
> I read the first row (X=1, Y=2) into a CMP Entity Bean and
> overwrite y with
> the Integer 4 (only inside the Entity Bean)
> Now I call a finder method for y (declared with something
> like findByY(int
> y) "y= {0}")
> FooEntityHome.findByY(4);
>
> Question: What happens inside a container, when I call this finder?
It depends.
> 1. The Entity bean is written (with a real UPDATE sql command) to the
> database, then a "SELECT x,y FROM Foo where y=<my y>" is
> executed and Entity
> Beans are constructed to return them in the result
If your container supports eager updating of the database and is configured
to do so, then this is what happens.
> 2. All rows of this table are loaded into Entity Beans, then
> the y variable
> in the Entity Beans are iteratively looked through?
I would imagine that this would be prohibitively expensive.
> 3. something else?
Yes. If the container supports delaying updates until the end of the
transaction (and I believe most do), and is configured for it (again, I
believe most do it this way, it's the most efficient), then the select
executes and your bean with its updated data is not found. In other words,
inconsistent results are returned. Something to watch out for.
>
> If I have 1 Billion rows in table Foo, option 2 is impossible
> of course,
> but if option 1 is used, a real sql-SELECT is done in every
> case, so where's
> the speed of the Entity Bean's cached data?
Not in finders, apparently. Possibly in development time.
>
> Maybe the implementations switch between option 1 and 2,
> depending on the
> number of rows in the table...
>
> Any comments?
I really dislike the way finders bypass the cache when delayed updates are
used.
A clever implementation could write out all beans which participate in a
transaction when a finder is invoked in that transaction.
- Avi
--
s/\be(\w+)/e-\1/g;
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".