on-find read-ahead
jivkoto Oct 31, 2005 4:37 AMHi,
It seems that on-find read-ahead do not work properly.
I have entity with 3 fields (2 of them is primary key). I am trying to use on-find read-ahead. And I expect that everything will be loaded when I call my findAll method. But instead of this there is one Select statement for everything. And N queries that loads the other field from the DB for every primary key. Which acts as on-load. Here is the log from the jboss console:
10:17:39,046 DEBUG [EAttachmentToProcess#findAll] Executing SQL: SELECT t0_a.cAt
tachId, t0_a.cProcessId, t0_a.cActId FROM tBPAttachProc t0_a
10:17:39,250 DEBUG [EAttachmentToProcess] Executing SQL: SELECT cActId FROM tBPA
ttachProc WHERE (cAttachId=? AND cProcessId=?)
10:17:39,265 DEBUG [EAttachmentToProcess] Executing SQL: SELECT cActId FROM tBPA
ttachProc WHERE (cAttachId=? AND cProcessId=?)
?? N TIMES
As you see it is in the same transaction @ejb.transaction type="Required" (as noted in the Forum). Other thing is that I try and load-group for the activityId which is not in the PK for this table, and guess ? nothing changed. N+1 queries each time. It is killing me?
Additional info: This is JBoss 3.2.6 on Windows XP
Here comes my xDocleted entity.
package com.some.attachment;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
/**
* Entity representing the relation many-to-many between attachments and process instances
*
* Standard entity bean, provides two finder methods (besides findByPK)- by attachment id
* and by process id.
*
* @author nts
* @version $Revision: 1.5 $
*
* @ejb.bean name = "EAttachmentToProcess"
* type="CMP"
* local-jndi-name="ejb/EAttachmentToProcessLocal"
* jndi-name="ejb/EAttachmentToProcess"
* prim-key-class="com.some.attachment.EAttachmentToProcessPK"
* view-type="both"
* cmp-version="2.x"
*
* @ejb.finder signature = "java.util.Collection findByAttachemntId(java.lang.String attachmentId)"
* query = "SELECT Object(a) FROM EAttachmentToProcess a WHERE a.attachmentId = ?1"
*
* @ejb.finder signature = "java.util.Collection findByProcessId(java.lang.String processId)"
* query = "SELECT Object(a) FROM EAttachmentToProcess a WHERE a.processId = ?1"
*
* @ejb.finder signature = "java.util.Collection findAll()"
* query = "SELECT Object(a) FROM EAttachmentToProcess a"
*
* @jboss.query signature ="java.util.Collection findAll()"
* query = "SELECT Object(a) FROM EAttachmentToProcess a"
* strategy = "on-find"
*
* @ejb.transaction
* type="Required"
*
* @ejb.permission role-name="admin"
*
* @ejb.persistence table-name = "tBPAttachProc"
*
* JBoss specific
*
* @jboss.persistence table-name = "tBPAttachProc" create-table = "false"
*
* @jboss.container-configuration name="EntityBean_Commit_A"
* @jboss.read-ahead strategy="on-find"
*
* @jboss.entity-command name = "no-select-before-insert"
*
*/
public abstract class EAttachmentToProcessEJB
implements EntityBean
{
private static final long serialVersionUID = 20050119L;
private transient EntityContext context;
/**
* Part of the PK and also a FK to tAttachment
*
* @return
*
* @ejb.interface-method view-type = "both"
* @ejb.persistence column-name = "cAttachId"
* jdbc-type="CHAR"
* sql-type="CHAR(36)"
*
*/
public abstract String getAttachmentId();
/**
*
* @param id
*
* @ejb.interface-method view-type = "both"
* @ejb.persistence column-name = "cAttachId"
* jdbc-type="CHAR"
* sql-type="CHAR(36)"
*
*/
public abstract void setAttachmentId(String id);
/**
* Part of the PK and also a FK to tProcInstance
*
* @return
*
* @ejb.interface-method view-type = "both"
* @ejb.persistence column-name = "cProcessId"
* jdbc-type="CHAR"
* sql-type="CHAR(36)"
*
*/
public abstract String getProcessId();
/**
*
* @param id
*
* @ejb.interface-method view-type = "both"
* @ejb.persistence column-name = "cProcessId"
* jdbc-type="CHAR"
* sql-type="CHAR(36)"
*/
public abstract void setProcessId(String id);
/**
* Additional info - id of the activity (receive, invoke ...)
* @return
*
* @ejb.interface-method view-type = "both"
* @ejb.persistence column-name = "cActId"
* jdbc-type= "VARCHAR"
* sql-type= "VARCHAR(512)"
*
*/
public abstract String getActivityId();
/**
* @ejb.interface-method view-type = "both"
* @ejb.persistence column-name = "cActId"
* jdbc-type= "VARCHAR"
* sql-type= "VARCHAR(512)"
*/
public abstract void setActivityId(String id);
/**
* @ejb.create-method view-type = "both"
*/
public EAttachmentToProcessPK ejbCreate(String attId, String procId, String actId)
throws CreateException
{
setAttachmentId(attId);
setProcessId(procId);
setActivityId(actId);
EAttachmentToProcessPK pk = new EAttachmentToProcessPK(attId, procId);
return pk;
}
????. and so on
}
Here is snipet of my jbosscmp-jdbc.xml generated file
<ejb-name>EAttachmentToProcess</ejb-name>
<create-table>false</create-table>
<read-ahead>
on-find
</read-ahead>
<table-name>tBPAttachProc</table-name>
<cmp-field>
<field-name>attachmentId</field-name>
<column-name>cAttachId</column-name>
<jdbc-type>CHAR</jdbc-type>
<sql-type>CHAR(36)</sql-type>
</cmp-field>
<cmp-field>
<field-name>processId</field-name>
<column-name>cProcessId</column-name>
<jdbc-type>CHAR</jdbc-type>
<sql-type>CHAR(36)</sql-type>
</cmp-field>
<cmp-field>
<field-name>activityId</field-name>
<column-name>cActId</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(512)</sql-type>
</cmp-field>
<query-method>
<method-name>findAll</method-name>
<method-params>
</method-params>
</query-method>
<jboss-ql>[CDATA[SELECT Object(a) FROM EAttachmentToProcess a]]</jboss-ql>
<read-ahead>
on-find
</read-ahead>
<entity-command name="no-select-before-insert">
</entity-command>
So if you help it will be great. If you say that there is bug is ok too. I just want to know where is the problem is it my fault?
Best regards, Zhivko