You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Juergen Saar <ju...@jsaar.org> on 2009/05/28 16:16:58 UTC
Sometimes no data from Relation to small tables
Hi,
there is strange behavior on 1:1 Relations where the target-table has only a
small amount of data.
In this cases I can see in the logfile, that there is no select for data at
all.
I found a workaround ... I do an explizit select ... this works
but the relation always brings hollow object
perhaps it brings a little more understandin of the problem:
One more thing: I turn caching off, because there is
more Software on the System that works with this data.
The Code Sniplet:
I overwrite the readProperty from CayenneDataObject
in my derived Class named MwareBusinessObject
the 'expressionForRelation' is a helper working on base og the
Cayenne-Configuration
public Object readProperty(String propName) {
Object result = null;
try {
result = super.readProperty(propName);
...
if (result != null) {
...
} else if (result instanceof MwareBusinessObject) {
/*
* @WORKAROUND
*/
MwareBusinessObject bobj = (MwareBusinessObject) result;
if (bobj.getPersistenceState() ==
PersistenceState.HOLLOW) {
Expression ex =
CayenneUtils.expressionForRelation(this, propName);
SelectQuery query = new
SelectQuery(result.getClass(), ex);
List tmp = getDataContext().performQuery(query);
if (tmp.size() == 1) {
result = tmp.get(0);
}
}
}
}
} catch (Exception e) {
...
My Cayenne-Version is 2.0.4
Sorry for not having tested the Problem with Version 3
-Juergen-
Re: Sometimes no data from Relation to small tables
Posted by Andrus Adamchik <an...@objectstyle.org>.
On May 29, 2009, at 1:43 PM, Andrus Adamchik wrote:
>>
>> The modeler says no dependent PK
>> In all cases (actual 3) where this problem exists, the relation-
>> target is a
>> kind of enumeration.
>> The relation points from nonPK-attribute to the PK (1 attribute) of
>> the
>> enumeration-Table
>
> Can you mark the nonPK attribute as PK in Cayenne (even though it is
> not), and check corresponding "toDep PK" checkbox? I suspect this is
> where the problem lies.
Or alternatively make it 1..N where nonPK column is an FK (it looks
like it is from your description, isn't it?)
Andrus
Re: Sometimes no data from Relation to small tables
Posted by Juergen Saar <ju...@jsaar.org>.
2009/5/29 Andrus Adamchik <an...@objectstyle.org>
>
> On May 29, 2009, at 12:07 PM, Juergen Saar wrote:
>
> The modeler says no dependent PK
>> In all cases (actual 3) where this problem exists, the relation-target is
>> a
>> kind of enumeration.
>> The relation points from nonPK-attribute to the PK (1 attribute) of the
>> enumeration-Table
>>
>
> Can you mark the nonPK attribute as PK in Cayenne (even though it is not),
> and check corresponding "toDep PK" checkbox? I suspect this is where the
> problem lies.
Sorry ... no effect
Especially strange: In all 3 constellation that show this problem
> the Target-Table has less than 20 rows.
>
Very likely the size of the target table is pure coincidence. I can't think
> of any logic in Cayenne that would depend on the table size.
Yes, I know it sounds esotheric
but in the past we had several problems round about
the cayenne cache ... even if disabled
some behavior pointed to the cache
So I suggested there might be a logic in cayenne
that puts all little tables to cache on starting cayenne
>
> Andrus
>
Re: Sometimes no data from Relation to small tables
Posted by Andrus Adamchik <an...@objectstyle.org>.
On May 29, 2009, at 12:07 PM, Juergen Saar wrote:
> The modeler says no dependent PK
> In all cases (actual 3) where this problem exists, the relation-
> target is a
> kind of enumeration.
> The relation points from nonPK-attribute to the PK (1 attribute) of
> the
> enumeration-Table
Can you mark the nonPK attribute as PK in Cayenne (even though it is
not), and check corresponding "toDep PK" checkbox? I suspect this is
where the problem lies.
> Especially strange: In all 3 constellation that show this problem
> the Target-Table has less than 20 rows.
Very likely the size of the target table is pure coincidence. I can't
think of any logic in Cayenne that would depend on the table size.
Andrus
Re: Sometimes no data from Relation to small tables
Posted by Juergen Saar <ju...@jsaar.org>.
The modeler says no dependent PK
In all cases (actual 3) where this problem exists, the relation-target is a
kind of enumeration.
The relation points from nonPK-attribute to the PK (1 attribute) of the
enumeration-Table
Especially strange: In all 3 constellation that show this problem
the Target-Table has less than 20 rows.
In my Tests, there seems to be a dependency to a small count of data in the
target-table
My assumption was a kind of interference of disabled cache and very small
table
but I wasn't able to proof ist.
2009/5/29 Andrus Adamchik <an...@objectstyle.org>
> Strange. How is the relationship mapped? Is this a PK to dependent PK?
>
> Andrus
>
>
>
> On May 28, 2009, at 5:16 PM, Juergen Saar wrote:
>
> Hi,
>>
>> there is strange behavior on 1:1 Relations where the target-table has only
>> a
>> small amount of data.
>> In this cases I can see in the logfile, that there is no select for data
>> at
>> all.
>>
>> I found a workaround ... I do an explizit select ... this works
>> but the relation always brings hollow object
>> perhaps it brings a little more understandin of the problem:
>>
>> One more thing: I turn caching off, because there is
>> more Software on the System that works with this data.
>>
>> The Code Sniplet:
>>
>> I overwrite the readProperty from CayenneDataObject
>> in my derived Class named MwareBusinessObject
>> the 'expressionForRelation' is a helper working on base og the
>> Cayenne-Configuration
>>
>> public Object readProperty(String propName) {
>> Object result = null;
>> try {
>> result = super.readProperty(propName);
>> ...
>> if (result != null) {
>> ...
>> } else if (result instanceof MwareBusinessObject) {
>> /*
>> * @WORKAROUND
>> */
>> MwareBusinessObject bobj = (MwareBusinessObject) result;
>> if (bobj.getPersistenceState() ==
>> PersistenceState.HOLLOW) {
>> Expression ex =
>> CayenneUtils.expressionForRelation(this, propName);
>> SelectQuery query = new
>> SelectQuery(result.getClass(), ex);
>> List tmp = getDataContext().performQuery(query);
>> if (tmp.size() == 1) {
>> result = tmp.get(0);
>> }
>> }
>> }
>> }
>> } catch (Exception e) {
>> ...
>>
>>
>> My Cayenne-Version is 2.0.4
>>
>> Sorry for not having tested the Problem with Version 3
>> -Juergen-
>>
>
>
Re: Sometimes no data from Relation to small tables
Posted by Andrus Adamchik <an...@objectstyle.org>.
Strange. How is the relationship mapped? Is this a PK to dependent PK?
Andrus
On May 28, 2009, at 5:16 PM, Juergen Saar wrote:
> Hi,
>
> there is strange behavior on 1:1 Relations where the target-table
> has only a
> small amount of data.
> In this cases I can see in the logfile, that there is no select for
> data at
> all.
>
> I found a workaround ... I do an explizit select ... this works
> but the relation always brings hollow object
> perhaps it brings a little more understandin of the problem:
>
> One more thing: I turn caching off, because there is
> more Software on the System that works with this data.
>
> The Code Sniplet:
>
> I overwrite the readProperty from CayenneDataObject
> in my derived Class named MwareBusinessObject
> the 'expressionForRelation' is a helper working on base og the
> Cayenne-Configuration
>
> public Object readProperty(String propName) {
> Object result = null;
> try {
> result = super.readProperty(propName);
> ...
> if (result != null) {
> ...
> } else if (result instanceof MwareBusinessObject) {
> /*
> * @WORKAROUND
> */
> MwareBusinessObject bobj = (MwareBusinessObject)
> result;
> if (bobj.getPersistenceState() ==
> PersistenceState.HOLLOW) {
> Expression ex =
> CayenneUtils.expressionForRelation(this, propName);
> SelectQuery query = new
> SelectQuery(result.getClass(), ex);
> List tmp = getDataContext().performQuery(query);
> if (tmp.size() == 1) {
> result = tmp.get(0);
> }
> }
> }
> }
> } catch (Exception e) {
> ...
>
>
> My Cayenne-Version is 2.0.4
>
> Sorry for not having tested the Problem with Version 3
> -Juergen-