Thanks Tobias -- I agree that it would reduce my wasteful queries if I could
combine the primary key acquisition and the entity bean reference generation
into a single finder method. 

However I face two problems here. 1. I am using CMP and really don't want to
go to BMP, and 2. The finder method would have to query a different table
than the table that the entity bean is wrapping. 

If there were a way to define a CMP finder method that queries a different
table than the one the entity bean is wrapping (e.g. let me write a full SQL
statement rather than just a WHERE clause), then I'd be in business. Is
there a way to do this with JOnAS?

Thank you much,
Bryan

-----Original Message-----
From: Tobias Seelinger [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 10, 2000 1:19 AM
To: [EMAIL PROTECTED]
Subject: Re: How to short-cut findByPrimaryKey?


If you only want to change your primary keys into remote references, let
the EJB Container do this job for you. You have to write a finder method
in your entity bean which selects the same IDs as your direct JDBC
query. The return value could be a java.util.Collection and it contains
the remote references. You get the references with only one DB query. If
your query is not too complex this has to work with BMP and CMP.

The wasteful part appears when you call get() methods on the references.
So if you are reading more columns than the primary key and you have to
read n rows this results in n+1 DB querys.

Tobias

Bryan Field-Elliot schrieb:
> 
> This question is one of optimization and improving performance:
> 
> I need to create an array of entity bean references. I already have an
array
> of primary keys, which I get from a direct JDBC query. I need to convert
> these primary keys into entity bean references. The "obvious" way to do
this
> is to iterate through the array and call "findByPrimaryKey" for each of
> these references. However, this results in what appears to be a wasteful
> query, for every call to findByPrimary Key:
> 
> select id from my_table where id = ?
> 
> This is useless, and yet it gets called with every call to
findByPrimaryKey.
> The rest of the columns are only pulled in when the client actually calls
> one of the get() methods on my beans:
> 
> select col1, col2, col3, ... from my_table where id = ?
> 
> So you see, I'd like to skip the calling of the first query altogether. Is
> there a way I can do this with JOnAS?
> 
> By the way, these are CMP entity beans. I suspect I can get the behavior I
> want with BMP, but I would like to stay CMP if at all possible (saves a
lot
> of work).
> 
> Thank you,
> Bryan
----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".
----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".

Reply via email to