You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by John Huss <jo...@gmail.com> on 2012/02/22 20:44:02 UTC

Auto-creation of reverse relationships

When I start up my Cayenne app, I see messages about it adding reverse
relationships in places where I have chosen not to define them in the
DataMap.  I'm wondering why it does this and if it is necessary and if it
can be turned off.  Here is the message I'm talking about:

2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
DbRelationship from Master to Detail

2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
ObjRelationship from Master to Detail


Thanks,

John

Re: Auto-creation of reverse relationships

Posted by Michael Gentry <mg...@masslight.net>.
Hi Joe,

EOF had a problem with unintentionally (or unexpectedly) fired faults
loading in extra records (yes, potentially millions), especially when
using addObjectToBothSidesOfRelationshipWithKey, but I've not seen
this happen in Cayenne and I believe I recall Andrus saying it doesn't
happen unless you explicitly trigger a fault -- such as
state.getAddresses().  If you have an Address and do
address.setState(state) you should be fine, even if you have an
explicit or complimentary relationship going the other way (State ->>
Address).

mrg


On Tue, Feb 28, 2012 at 9:05 PM, Joseph Senecal <se...@apple.com> wrote:
> My concern with the automatic reverse relationships is if adding an object fires a fault. Firing a fault on a small dimension table could result in attempting to load millions of records from the detail table into memory. As long as the automatic reverse relationship doesn't do that, I don't care.
>
> Joe
>
> On Feb 28, 2012, at 4:54 PM, Michael Gentry wrote:
>
>> Hi John,
>>
>> I don't know the answer to your question offhand, but what is the harm
>> that is being caused from your perspective (aside from extra logs on
>> startup)?
>>
>> Thanks,
>>
>> mrg
>>
>>
>> On Tue, Feb 28, 2012 at 5:45 PM, John Huss <jo...@gmail.com> wrote:
>>> This comes from EntityResolver.applyDBLayerDefaults().  The commit where
>>> this was introduced (Revision 606720) says:
>>>
>>> "JPA: adding extra step - connecting reverse relationships on Cayenne end
>>> for consistent runtime..."
>>>
>>> So is it OK to turn this off?  Or will things blow up?
>>>
>>> Thanks,
>>> John
>>>
>>> On Wed, Feb 22, 2012 at 1:44 PM, John Huss <jo...@gmail.com> wrote:
>>>
>>>> When I start up my Cayenne app, I see messages about it adding reverse
>>>> relationships in places where I have chosen not to define them in the
>>>> DataMap.  I'm wondering why it does this and if it is necessary and if it
>>>> can be turned off.  Here is the message I'm talking about:
>>>>
>>>> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
>>>> DbRelationship from Master to Detail
>>>>
>>>> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
>>>> ObjRelationship from Master to Detail
>>>>
>>>>
>>>> Thanks,
>>>>
>>>> John
>>>>
>

Re: Auto-creation of reverse relationships

Posted by Joseph Senecal <se...@apple.com>.
My concern with the automatic reverse relationships is if adding an object fires a fault. Firing a fault on a small dimension table could result in attempting to load millions of records from the detail table into memory. As long as the automatic reverse relationship doesn't do that, I don't care.

Joe

On Feb 28, 2012, at 4:54 PM, Michael Gentry wrote:

> Hi John,
> 
> I don't know the answer to your question offhand, but what is the harm
> that is being caused from your perspective (aside from extra logs on
> startup)?
> 
> Thanks,
> 
> mrg
> 
> 
> On Tue, Feb 28, 2012 at 5:45 PM, John Huss <jo...@gmail.com> wrote:
>> This comes from EntityResolver.applyDBLayerDefaults().  The commit where
>> this was introduced (Revision 606720) says:
>> 
>> "JPA: adding extra step - connecting reverse relationships on Cayenne end
>> for consistent runtime..."
>> 
>> So is it OK to turn this off?  Or will things blow up?
>> 
>> Thanks,
>> John
>> 
>> On Wed, Feb 22, 2012 at 1:44 PM, John Huss <jo...@gmail.com> wrote:
>> 
>>> When I start up my Cayenne app, I see messages about it adding reverse
>>> relationships in places where I have chosen not to define them in the
>>> DataMap.  I'm wondering why it does this and if it is necessary and if it
>>> can be turned off.  Here is the message I'm talking about:
>>> 
>>> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
>>> DbRelationship from Master to Detail
>>> 
>>> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
>>> ObjRelationship from Master to Detail
>>> 
>>> 
>>> Thanks,
>>> 
>>> John
>>> 


Re: Auto-creation of reverse relationships

Posted by John Huss <jo...@gmail.com>.
On Tue, Feb 28, 2012 at 10:34 PM, John Huss <jo...@gmail.com> wrote:

> My entity classes use explicit fields to store data instead of a Map, so
> when it tries to access the "runtimeRelationshipX" fields it blows up
> because these don't exist in the generated java classes.  I've dealt with
> it so far by just modeling all the relationships so that the fields are
> there to hold the data.  But now I'm using more introspection and having
> these unnecessary relationships is requiring workaround that I would prefer
> not to have.
>
> I did try turning this off today and thus far everything seems ok, but
> there is a lot more to test to be sure.
>

So, just to follow up on this...  I did run into some problems - one was
when adding some prefetches to a query it would look for the reverse
relationship and blow up.  There was another occurrence elsewhere too, but
I don't recall where.  So I turned back on the creation of the reverse
DbRelationships only and that seems to work well.  These "unneeded"
DbRelationships don't hurt anything and still keep my entity classes free
of accessors for relationships that I don't want.

So my question now is, it is ok if I submit a patch to make it optional to
create the reverse ObjRelationships?  I would probably use a property to
configure it, but maybe there is a better way.

Thanks,
John

Re: Auto-creation of reverse relationships

Posted by Andrus Adamchik <an...@objectstyle.org>.
The purpose of "runtime" relationships is to allow you to skip certain relationships from your data model. E.g. artist.paintings is an explicit to-many, but there may be no painting.artist. With runtime relationships there, adding a new painting to an artist would correctly update painting ARTIST_ID on save.

In a default CayenneDataObject situation auto-reverse relationships should do no harm (such as triggering fault fetches ... if they do, please report it, let's take a look). But generally they are an implementation detail, and if we come up with an alternative and less invasive algorithm to handle one-way relationships, I'll be happy to dump runtime rels.

Not using a "generic" object (CayenneDataObject) may cause an issue with runtime rels... Just turn them off, but be aware of consequences for one-way to-many relationships as mentioned above.

Andrus



On Feb 29, 2012, at 7:34 AM, John Huss wrote:
> My entity classes use explicit fields to store data instead of a Map, so
> when it tries to access the "runtimeRelationshipX" fields it blows up
> because these don't exist in the generated java classes.  I've dealt with
> it so far by just modeling all the relationships so that the fields are
> there to hold the data.  But now I'm using more introspection and having
> these unnecessary relationships is requiring workaround that I would prefer
> not to have.
> 
> I did try turning this off today and thus far everything seems ok, but
> there is a lot more to test to be sure.
> 
> On Tuesday, February 28, 2012, Michael Gentry wrote:
> 
>> Hi John,
>> 
>> I don't know the answer to your question offhand, but what is the harm
>> that is being caused from your perspective (aside from extra logs on
>> startup)?
>> 
>> Thanks,
>> 
>> mrg
>> 
>> 
>> On Tue, Feb 28, 2012 at 5:45 PM, John Huss <johnthuss@gmail.com<javascript:;>>
>> wrote:
>>> This comes from EntityResolver.applyDBLayerDefaults().  The commit where
>>> this was introduced (Revision 606720) says:
>>> 
>>> "JPA: adding extra step - connecting reverse relationships on Cayenne end
>>> for consistent runtime..."
>>> 
>>> So is it OK to turn this off?  Or will things blow up?
>>> 
>>> Thanks,
>>> John
>>> 
>>> On Wed, Feb 22, 2012 at 1:44 PM, John Huss <johnthuss@gmail.com<javascript:;>>
>> wrote:
>>> 
>>>> When I start up my Cayenne app, I see messages about it adding reverse
>>>> relationships in places where I have chosen not to define them in the
>>>> DataMap.  I'm wondering why it does this and if it is necessary and if
>> it
>>>> can be turned off.  Here is the message I'm talking about:
>>>> 
>>>> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
>>>> DbRelationship from Master to Detail
>>>> 
>>>> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
>>>> ObjRelationship from Master to Detail
>>>> 
>>>> 
>>>> Thanks,
>>>> 
>>>> John
>>>> 
>> 


Re: Field-based Persistent

Posted by John Huss <jo...@gmail.com>.
On Wed, Feb 29, 2012 at 1:47 AM, Andrus Adamchik <an...@objectstyle.org>wrote:

> So changing the topic, and taking to dev...
>
> On Feb 29, 2012, at 7:34 AM, John Huss wrote:
>
> > My entity classes use explicit fields to store data instead of a Map, so
> > when it tries to access the "runtimeRelationshipX" fields
>
> So these are on the server side (not the ROP client)? Did you write your
> own set of ClassDescriptors?
>

Both.  I use the same classes for both server and client because that is
really necessary for my use case.  It takes the ROP approach as a starting
point and adds back in the things you usually get from the server:
1) validation
2) change tracking

So I have a PersistentObject subclass called UniversalObject that adds the
snapshotVersion (which may be unnecessary), the validation methods, and
abstract methods for readPropertyDirectly and writePropertyDirectly.

I have a ValueHolderDescriptorFactory subclass that allows me to use a
subclass of SimpleAttributeProperty that takes care of
calling getObjectContext().propertyChanged on write.

This is hard to describe and hard to follow I'm sure.  When I have time I
can provide a minimal example if you want.


>
> I am working on improving the concurrency of a single DataContext
> (scenario being a single shared context in read-only apps), the Map
> structure of CayenneDataObject is one of the factors causing grief. So I am
> interested in discussing alternative implementations. One being field-based
> objects similar to ROP, another being using an Object[] instead of a Map to
> store mapped properties. Yet another - using a delegate for each Persistent
> (this will also let us drop a common superclass requirement).


It would be nice to have a standard API for how values are written and read
from the Objects, like DataObject.  It is easier (or at least more obvious)
to implement the interface than to try to tweak the descriptors.  That
would make it easier to try alternative approaches.

Field-based Persistent

Posted by Andrus Adamchik <an...@objectstyle.org>.
So changing the topic, and taking to dev... 

On Feb 29, 2012, at 7:34 AM, John Huss wrote:

> My entity classes use explicit fields to store data instead of a Map, so
> when it tries to access the "runtimeRelationshipX" fields

So these are on the server side (not the ROP client)? Did you write your own set of ClassDescriptors? 

I am working on improving the concurrency of a single DataContext (scenario being a single shared context in read-only apps), the Map structure of CayenneDataObject is one of the factors causing grief. So I am interested in discussing alternative implementations. One being field-based objects similar to ROP, another being using an Object[] instead of a Map to store mapped properties. Yet another - using a delegate for each Persistent (this will also let us drop a common superclass requirement).

Andrus

Re: Auto-creation of reverse relationships

Posted by John Huss <jo...@gmail.com>.
My entity classes use explicit fields to store data instead of a Map, so
when it tries to access the "runtimeRelationshipX" fields it blows up
because these don't exist in the generated java classes.  I've dealt with
it so far by just modeling all the relationships so that the fields are
there to hold the data.  But now I'm using more introspection and having
these unnecessary relationships is requiring workaround that I would prefer
not to have.

I did try turning this off today and thus far everything seems ok, but
there is a lot more to test to be sure.

On Tuesday, February 28, 2012, Michael Gentry wrote:

> Hi John,
>
> I don't know the answer to your question offhand, but what is the harm
> that is being caused from your perspective (aside from extra logs on
> startup)?
>
> Thanks,
>
> mrg
>
>
> On Tue, Feb 28, 2012 at 5:45 PM, John Huss <johnthuss@gmail.com<javascript:;>>
> wrote:
> > This comes from EntityResolver.applyDBLayerDefaults().  The commit where
> > this was introduced (Revision 606720) says:
> >
> > "JPA: adding extra step - connecting reverse relationships on Cayenne end
> > for consistent runtime..."
> >
> > So is it OK to turn this off?  Or will things blow up?
> >
> > Thanks,
> > John
> >
> > On Wed, Feb 22, 2012 at 1:44 PM, John Huss <johnthuss@gmail.com<javascript:;>>
> wrote:
> >
> >> When I start up my Cayenne app, I see messages about it adding reverse
> >> relationships in places where I have chosen not to define them in the
> >> DataMap.  I'm wondering why it does this and if it is necessary and if
> it
> >> can be turned off.  Here is the message I'm talking about:
> >>
> >> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
> >> DbRelationship from Master to Detail
> >>
> >> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
> >> ObjRelationship from Master to Detail
> >>
> >>
> >> Thanks,
> >>
> >> John
> >>
>

Re: Auto-creation of reverse relationships

Posted by Michael Gentry <mg...@masslight.net>.
Hi John,

I don't know the answer to your question offhand, but what is the harm
that is being caused from your perspective (aside from extra logs on
startup)?

Thanks,

mrg


On Tue, Feb 28, 2012 at 5:45 PM, John Huss <jo...@gmail.com> wrote:
> This comes from EntityResolver.applyDBLayerDefaults().  The commit where
> this was introduced (Revision 606720) says:
>
> "JPA: adding extra step - connecting reverse relationships on Cayenne end
> for consistent runtime..."
>
> So is it OK to turn this off?  Or will things blow up?
>
> Thanks,
> John
>
> On Wed, Feb 22, 2012 at 1:44 PM, John Huss <jo...@gmail.com> wrote:
>
>> When I start up my Cayenne app, I see messages about it adding reverse
>> relationships in places where I have chosen not to define them in the
>> DataMap.  I'm wondering why it does this and if it is necessary and if it
>> can be turned off.  Here is the message I'm talking about:
>>
>> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
>> DbRelationship from Master to Detail
>>
>> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
>> ObjRelationship from Master to Detail
>>
>>
>> Thanks,
>>
>> John
>>

Re: Auto-creation of reverse relationships

Posted by John Huss <jo...@gmail.com>.
This comes from EntityResolver.applyDBLayerDefaults().  The commit where
this was introduced (Revision 606720) says:

"JPA: adding extra step - connecting reverse relationships on Cayenne end
for consistent runtime..."

So is it OK to turn this off?  Or will things blow up?

Thanks,
John

On Wed, Feb 22, 2012 at 1:44 PM, John Huss <jo...@gmail.com> wrote:

> When I start up my Cayenne app, I see messages about it adding reverse
> relationships in places where I have chosen not to define them in the
> DataMap.  I'm wondering why it does this and if it is necessary and if it
> can be turned off.  Here is the message I'm talking about:
>
> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
> DbRelationship from Master to Detail
>
> 2012-02-22 19:43:02 EntityResolver [INFO] added runtime complimentary
> ObjRelationship from Master to Detail
>
>
> Thanks,
>
> John
>