Ok thanks to help me :
##
## Query
##
MasterSchedule.getById(...)
##
## CODE
##
public static MasterSchedule getById(ObjectContext context, Integer
skdId) throws OpconException {
List<MasterSchedule> skdList =
MasterSchedule.getByExpression(context, ExpressionFactory.matchExp(
MasterSchedule.SCHEDULE_ID_PROPERTY, skdId));
if (skdList != null && skdList.size() > 0) {
return skdList.get(0);
}
return null;
}
public static List<MasterSchedule> getByExpression(ObjectContext
context, Expression filter) throws OpconException {
SelectQuery query;
if (filter != null) {
query = new SelectQuery(MasterSchedule.class, filter);
} else {
query = new SelectQuery(MasterSchedule.class);
}
query.addPrefetch(RELATED_MASTER_SCHEDULE_AUX_PROPERTY);
try {
return context.performQuery(query);
} catch (CayenneRuntimeException e) {
throw new OpconException("MasterSchedule:getByExpression()
problem : " + e.getUnlabeledMessage(), e);
}
}
##
## XML
##
<db-entity name="SNAME" schema="dbo" catalog="opconxps4">
<db-attribute name="SKDID" type="INTEGER" isPrimaryKey="true"
isMandatory="true" length="10"/>
<db-attribute name="SKDNAME" type="VARCHAR" isMandatory="true"
length="255"/>
<db-attribute name="SKDSAM" type="SMALLINT" isMandatory="true"
length="5"/>
<db-attribute name="SKDSTART" type="REAL" isMandatory="true"
length="24"/>
<db-attribute name="SKDWKDAYS" type="SMALLINT"
isMandatory="true" length="5"/>
</db-entity>
<db-entity name="SNAME_AUX" schema="dbo" catalog="opconxps4">
<db-attribute name="SAFC" type="SMALLINT" isPrimaryKey="true"
isMandatory="true" length="5"/>
<db-attribute name="SASEQNO" type="SMALLINT" isPrimaryKey="true"
isMandatory="true" length="5"/>
<db-attribute name="SAVALUE" type="VARCHAR" isMandatory="true"
length="4000"/>
<db-attribute name="SKDID" type="INTEGER" isPrimaryKey="true"
isMandatory="true" length="10"/>
</db-entity>
<obj-entity name="MasterSchedule"
className="com.sma.core.api.master.MasterSchedule" dbEntityName="SNAME"
superClassName="com.sma.core.api.DataAccessObject">
<obj-attribute name="scheduleId" type="java.lang.Integer"
db-attribute-path="SKDID"/>
<obj-attribute name="scheduleName" type="java.lang.String"
db-attribute-path="SKDNAME"/>
<obj-attribute name="scheduleSam" type="java.lang.Short"
db-attribute-path="SKDSAM"/>
<obj-attribute name="scheduleStart" type="java.lang.Float"
db-attribute-path="SKDSTART"/>
<obj-attribute name="scheduleWorkingDays" type="java.lang.Short"
db-attribute-path="SKDWKDAYS"/>
</obj-entity>
<obj-entity name="MasterScheduleAux"
className="com.sma.core.api.auxs.MasterScheduleAux"
dbEntityName="SNAME_AUX" superClassName="com.sma.core.api.DataAccessObject">
<obj-attribute name="ScheduleId" type="java.lang.Integer"
db-attribute-path="SKDID"/>
<obj-attribute name="safc" type="java.lang.Short"
db-attribute-path="SAFC"/>
<obj-attribute name="saseqno" type="java.lang.Short"
db-attribute-path="SASEQNO"/>
<obj-attribute name="savalue" type="java.lang.String"
db-attribute-path="SAVALUE"/>
</obj-entity>
<obj-relationship name="relatedMasterScheduleAux"
source="MasterSchedule" target="MasterScheduleAux"
db-relationship-path="toMasterScheduleAux"/>
<db-relationship name="toMasterScheduleAux" source="SNAME"
target="SNAME_AUX" toMany="true">
<db-attribute-pair source="SKDID" target="SKDID"/>
</db-relationship>
##
## Results
##
--- will run 2 queries.
--- transaction started.
SELECT t0.SKDID, t0.SKDSAM, t0.SKDNAME, t0.SKDSTART, t0.SKDWKDAYS FROM
dbo.SNAME t0 WHERE t0.SKDID = ? [bind: 1->SKDID:29]
=== returned 1 row. - took 32 ms.
SELECT t0.SAFC, t0.SKDID, t0.SAVALUE, t0.SASEQNO FROM dbo.SNAME_AUX t0
JOIN dbo.SNAME t1 ON (t0.SKDID = t1.SKDID) WHERE t1.SKDID = ? [bind:
1->SKDID:29]
=== returned 8 rows. - took 32 ms.
+++ transaction committed.
--- will run 1 query.
--- transaction started.
SELECT DISTINCT t0.SKDID, t0.SKDSAM, t0.SKDNAME, t0.SKDSTART,
t0.SKDWKDAYS FROM dbo.SNAME t0 JOIN dbo.SNAME_AUX t1 ON (t0.SKDID =
t1.SKDID) WHERE t1.SKDID = ? AND t1.SASEQNO = ? AND t1.SAFC = ? [bind:
1->SKDID:29, 2->SASEQNO:1, 3->SAFC:0]
=== returned 1 row. - took 31 ms.
+++ transaction committed.
--- will run 1 query.
--- transaction started.
SELECT DISTINCT t0.SKDID, t0.SKDSAM, t0.SKDNAME, t0.SKDSTART,
t0.SKDWKDAYS FROM dbo.SNAME t0 JOIN dbo.SNAME_AUX t1 ON (t0.SKDID =
t1.SKDID) WHERE t1.SKDID = ? AND t1.SASEQNO = ? AND t1.SAFC = ? [bind:
1->SKDID:29, 2->SASEQNO:1, 3->SAFC:105]
=== returned 1 row. - took 31 ms.
+++ transaction committed.
--- will run 1 query.
--- transaction started.
SELECT DISTINCT t0.SKDID, t0.SKDSAM, t0.SKDNAME, t0.SKDSTART,
t0.SKDWKDAYS FROM dbo.SNAME t0 JOIN dbo.SNAME_AUX t1 ON (t0.SKDID =
t1.SKDID) WHERE t1.SKDID = ? AND t1.SASEQNO = ? AND t1.SAFC = ? [bind:
1->SKDID:29, 2->SASEQNO:1, 3->SAFC:106]
=== returned 1 row. - took 12 ms.
+++ transaction committed.
--- will run 1 query.
--- transaction started.
SELECT DISTINCT t0.SKDID, t0.SKDSAM, t0.SKDNAME, t0.SKDSTART,
t0.SKDWKDAYS FROM dbo.SNAME t0 JOIN dbo.SNAME_AUX t1 ON (t0.SKDID =
t1.SKDID) WHERE t1.SKDID = ? AND t1.SASEQNO = ? AND t1.SAFC = ? [bind:
1->SKDID:29, 2->SASEQNO:1, 3->SAFC:107]
=== returned 1 row. - took 12 ms.
+++ transaction committed.
--- will run 1 query.
--- transaction started.
SELECT DISTINCT t0.SKDID, t0.SKDSAM, t0.SKDNAME, t0.SKDSTART,
t0.SKDWKDAYS FROM dbo.SNAME t0 JOIN dbo.SNAME_AUX t1 ON (t0.SKDID =
t1.SKDID) WHERE t1.SKDID = ? AND t1.SASEQNO = ? AND t1.SAFC = ? [bind:
1->SKDID:29, 2->SASEQNO:1, 3->SAFC:109]
=== returned 1 row. - took 12 ms.
+++ transaction committed.
--- will run 1 query.
--- transaction started.
SELECT DISTINCT t0.SKDID, t0.SKDSAM, t0.SKDNAME, t0.SKDSTART,
t0.SKDWKDAYS FROM dbo.SNAME t0 JOIN dbo.SNAME_AUX t1 ON (t0.SKDID =
t1.SKDID) WHERE t1.SKDID = ? AND t1.SASEQNO = ? AND t1.SAFC = ? [bind:
1->SKDID:29, 2->SASEQNO:1, 3->SAFC:111]
=== returned 1 row. - took 31 ms.
+++ transaction committed.
--- will run 1 query.
--- transaction started.
SELECT DISTINCT t0.SKDID, t0.SKDSAM, t0.SKDNAME, t0.SKDSTART,
t0.SKDWKDAYS FROM dbo.SNAME t0 JOIN dbo.SNAME_AUX t1 ON (t0.SKDID =
t1.SKDID) WHERE t1.SKDID = ? AND t1.SASEQNO = ? AND t1.SAFC = ? [bind:
1->SKDID:29, 2->SASEQNO:1, 3->SAFC:112]
=== returned 1 row. - took 27 ms.
+++ transaction committed.
--- will run 1 query.
--- transaction started.
SELECT DISTINCT t0.SKDID, t0.SKDSAM, t0.SKDNAME, t0.SKDSTART,
t0.SKDWKDAYS FROM dbo.SNAME t0 JOIN dbo.SNAME_AUX t1 ON (t0.SKDID =
t1.SKDID) WHERE t1.SKDID = ? AND t1.SASEQNO = ? AND t1.SAFC = ? [bind:
1->SKDID:29, 2->SASEQNO:1, 3->SAFC:113]
=== returned 1 row. - took 32 ms.
+++ transaction committed.
Andrus Adamchik wrote:
>
> On Jul 15, 2008, at 6:10 PM, Laurent Marchal wrote:
>
>> In fact it does a little because the Artist_AUX list is well in sync
>> with the database.
>> But now each time i use the Artist object Cayenne do 1 request for
>> each related Artist_AUX row !
>> That was the thing i wanted to avoid....
>
> This is strange. Totally not how I would expect prefetching to work.
> Which version of Cayenne is this?
>
>> I attached the logs, where Artist is dbo.SNAME and Artist_AUX is
>> dbo.SNAME_AUX.
>
> Attachments are stripped from the list. Could you possibly post in the
> list message body a few chunks of info to help us identify the problem:
>
> * the piece of code executing the query
> * relevant pieces of logs
> * the part of the DataMap XML showing the entities in question and how
> the relationship is mapped
>
> Thanks,
> Andrus
>
>
>
This archive was generated by hypermail 2.0.0 : Tue Jul 15 2008 - 11:44:56 EDT