What you're seeing is a design decision to use "lazy" data retrieval. I don't know whether all EJB containers use this approach, but I wouldn't be surprised, since the implementations for ejbFind methods return primary keys rather than entire beans.
For what it's worth, this approach can work really well when paging through a large volume of rows.
I could be wrong, but I don't believe that there is any way for you to change the behavior you describe. If you want to retrieve the data with a single select, you'll probably need to use straight JDBC rather using an entity beans finder method.
I tried the same kind of scenario on another application and it actually worked perfectly well this time.
The different read-ahead strategies gave the following results:
1. none - One select per entity
2. on-load One select per number of page-size entities. page-size is an element of the read-ahead element (jbosscmp-jdbc.xml) that specifies the number of entities to read in a chunk.
3. on-find Only one single query for the entire find operation including data loading.
I do a findByName(String name) and then invoke some getter methods on the local interfaces obtained in the finder method.
I will now return to the original application and try again.
BTW: It is true that BMP finder methods return primary keys and it's quite another story in the BMP case.
However, when doing CMP the container can easily load the entities with data in the same operation that the finder executes.
Never mind, everything works just fine. I was a little bit too fast in posting the original message in this thread. Sorry !