EJB: ONE query for multiple rows

T

Timo Nentwig

Hi!

Beans are used to be fetched from DB by countless single SELECT statements
which I more than stupid.

This must be something I misunderstood about EJBs, isn't it possible to
fetch multiple rows/beans with one SELECT? Getting row after row will trash
performance of any DB and hence you could not even build mid-size system
with EJBs.
 
S

Sudsy

Timo said:
Hi!

Beans are used to be fetched from DB by countless single SELECT statements
which I more than stupid.

This must be something I misunderstood about EJBs, isn't it possible to
fetch multiple rows/beans with one SELECT? Getting row after row will trash
performance of any DB and hence you could not even build mid-size system
with EJBs.

I'm having to read a lot into your post since you don't offer much detail.
If you're talking about entity EJBs then investigate finder methods.
They can return collections of beans.
 
A

Andrew Thompson

See subject ("EJB: ..."). Yes, I'm talking about EJBs.

It's alway wise to repeat each word (or acronym)
of the subject in the body of your post.

A lot of folks (myself included) mostly
ignore the 'subject' line.

HTH
 
S

Sudsy

Timo said:
Sudsy wrote:




See subject ("EJB: ..."). Yes, I'm talking about EJBs.




Can you offer some more details?

The topic is complex and implementation depends on whether you're using
BMP or CMP. I just went to the Sun site and entered "+entity +finder
+method" as the query. The third hit is this one:
<http://java.sun.com/developer/onlineTraining/Programming/JDCBook/code5.html>
There's lots of reading to do, but the Sun site should always be one of
your first sources of information. I don't want to waste bandwidth on
this ng explaining what is already well-covered.
Best wishes!
 
T

Timo Nentwig

Ok, more precisely this time. I don't develop EJBs, I'm just wondering what
the EJB developer are telling me: the finder methods only get the IDs of
the rows, the row itself is actually fetch on first access. I.e. my finder
method may return the IDs of 1000 rows and then will fetch (SELECT) each
single one of them when I access them (i.e. iterator over the collection).

I can't believe that EJB is that silly...
 
S

Sudsy

Timo said:
Ok, more precisely this time. I don't develop EJBs, I'm just wondering what
the EJB developer are telling me: the finder methods only get the IDs of
the rows, the row itself is actually fetch on first access. I.e. my finder
method may return the IDs of 1000 rows and then will fetch (SELECT) each
single one of them when I access them (i.e. iterator over the collection).

I can't believe that EJB is that silly...

How do you mean "silly"? Entity beans exist to represent the state of a
row in a database table or view. Yes, finder methods return an array of
primary key objects to the J2EE container.
But the client receives a collection of local or remote interfaces. The
J2EE server handles the mapping and will populate entity EJBs from the
underlying table or view as needed.
Are you worried about the overhead? Performing a fetch by primary key
does not tax the DB as would a regular SELECT with constraints. But you
might want to consult the appropriate resources or run your own numbers
if you're unconvinced.
 
T

Timo Nentwig

Sudsy said:
How do you mean "silly"? Entity beans exist to represent the state of a

I likely use all the rows I find with the finder method (hence "finder"
method as it does find what I am looking for). So, why does the container
fetch one row after another?
 
S

Sudsy

Timo said:
I likely use all the rows I find with the finder method (hence "finder"
method as it does find what I am looking for). So, why does the container
fetch one row after another?

What happens when you use a ResultSet? Do you think all of the matching
rows are presented to your client at once? What then of the setFetchSize
method?
It's difficult to explain all the magic which goes on "under the covers"
which is why I suggested you find a good reference and do some reading.
Suffice it to say that entity beans are cached and re-used.
No sense boring everyone with the details. Most will likely never have
need for entity beans...
 
T

Timo Nentwig

Sudsy said:
What happens when you use a ResultSet? Do you think all of the matching
rows are presented to your client at once? What then of the setFetchSize
method?

It is ONE query that the database does process; setFetchsize() is only about
not holding all the data concurrently in RAM.

After all EJB is f*ckingly slow due to an endless count of single stupid
SELECTs fired at the RDBMS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top