Describe BeanManagedPersistence here: SQL CRUD is hard coded into a BMP entity bean (as opposed to using a deployment descriptor)
"Even to access an entity by its primary key, you have to go twice to the database."
Unless you add the ejbLoad() I do not think you have to go twice to the database:
public String ejbFindByPrimaryKey(String primaryKey) throws FinderException {
boolean haveResult = false; //...
String query = "select id from CUSTOMER where id = ? ";
PreparedStatement prepStatement = connection.prepareStatement(query);
prepStatement.setString(1, primaryKey);
haveResult = prepStatement.execute(); //...
if (! haveResult) {
throw new ObjectNotFoundException("No record found for Customer id: " + primaryKey );
},
return primaryKey;
The ejbLoad() call might be considered Lazy Initialization.
Unless ejbLoad() is called you don't have access to the Entity Bean by definition. So ejbLoad() will be called in 99% of the cases following the ejbFindByPrimaryKey(). Why do you think clients call ejbFindByPrimaryKey(), just to discard the resulting reference?
The N+1 hits was pretty silly - I cant defend that one.
Dave Hunter