You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Daniel Perry <d....@netcase.co.uk> on 2005/11/04 18:08:51 UTC
PB linking problem
Not sure if this is really an bug, or just a 'feature', but things dont get
linked under certain curcumstances.
I have two objects: activity, and attachment.
An activity has a collection of attachments.
/**
* @ojb.collection element-class-ref="com.netcase.pol.bo.Attachment"
* foreignkey="activityId"
*
query-customizer="com.netcase.ojb.NotDeletedQueryCustomizer"
* proxy="true" auto-retrieve="true" auto-update="object"
*/
private List<Attachment> attachments;
(attachment has: @ojb.field name="activityId" jdbc-type="INTEGER")
The following works: (ie, activityId is set properly)
1. persist an attachment.
2. add it to the collection in activity.
3. persist activity.
However, if i add the following to attachment:
/**
* @ojb.reference foreignkey="activityId"
*/
private Activity activity;
then the above doesnt work. activityId ends up as 0. I guess i should
expect this as activity is null. But, still, as activity is being persisted
last, shouldnt it be updated for that link?
Daniel.
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
RE: PB linking problem
Posted by Daniel Perry <d....@netcase.co.uk>.
ojb 1.0.3 and pb api.
To start with I wasnt setting the back reference (as when i wrote the code
it didnt have a back-reference).
I then added the back reference, which caused the problem. Setting the back
reference solves it.
I can understand why it does it - update activity generates activity id,
then it sets it in attachment, and saves attachment, causing it to check the
activity reference, and then change id back to null (0). It just seemed a
bit odd to start with.
Daniel.
> -----Original Message-----
> From: Armin Waibel [mailto:arminw@apache.org]
> Sent: 07 November 2005 09:45
> To: OJB Users List
> Subject: Re: PB linking problem
>
>
> Hi Daniel,
>
> which version of OJB and which API (PB-api or ODMG) do you use?
> Do you set the back-reference in attachment when adding to actitvity?
> ...
> activity.addAttachment(attachment);
> attachment.setActivity(activity);
> ...
>
> regards,
> Armin
>
> Daniel Perry wrote:
> > Not sure if this is really an bug, or just a 'feature', but
> things dont get
> > linked under certain curcumstances.
> >
> > I have two objects: activity, and attachment.
> >
> > An activity has a collection of attachments.
> >
> > /**
> > * @ojb.collection element-class-ref="com.netcase.pol.bo.Attachment"
> > * foreignkey="activityId"
> > *
> > query-customizer="com.netcase.ojb.NotDeletedQueryCustomizer"
> > * proxy="true" auto-retrieve="true"
> auto-update="object"
> > */
> > private List<Attachment> attachments;
> >
> > (attachment has: @ojb.field name="activityId" jdbc-type="INTEGER")
> >
> > The following works: (ie, activityId is set properly)
> > 1. persist an attachment.
> > 2. add it to the collection in activity.
> > 3. persist activity.
> >
> > However, if i add the following to attachment:
> > /**
> > * @ojb.reference foreignkey="activityId"
> > */
> > private Activity activity;
> >
> > then the above doesnt work. activityId ends up as 0. I guess i should
> > expect this as activity is null. But, still, as activity is
> being persisted
> > last, shouldnt it be updated for that link?
> >
> > Daniel.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: PB linking problem
Posted by Armin Waibel <ar...@apache.org>.
Hi Daniel,
which version of OJB and which API (PB-api or ODMG) do you use?
Do you set the back-reference in attachment when adding to actitvity?
...
activity.addAttachment(attachment);
attachment.setActivity(activity);
...
regards,
Armin
Daniel Perry wrote:
> Not sure if this is really an bug, or just a 'feature', but things dont get
> linked under certain curcumstances.
>
> I have two objects: activity, and attachment.
>
> An activity has a collection of attachments.
>
> /**
> * @ojb.collection element-class-ref="com.netcase.pol.bo.Attachment"
> * foreignkey="activityId"
> *
> query-customizer="com.netcase.ojb.NotDeletedQueryCustomizer"
> * proxy="true" auto-retrieve="true" auto-update="object"
> */
> private List<Attachment> attachments;
>
> (attachment has: @ojb.field name="activityId" jdbc-type="INTEGER")
>
> The following works: (ie, activityId is set properly)
> 1. persist an attachment.
> 2. add it to the collection in activity.
> 3. persist activity.
>
> However, if i add the following to attachment:
> /**
> * @ojb.reference foreignkey="activityId"
> */
> private Activity activity;
>
> then the above doesnt work. activityId ends up as 0. I guess i should
> expect this as activity is null. But, still, as activity is being persisted
> last, shouldnt it be updated for that link?
>
> Daniel.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
RE: PB linking problem
Posted by Daniel Perry <d....@netcase.co.uk>.
But surely it should update the activityId in the attachment object on
writing the activity (as activity has a collection of attachments, with
auto-update="object" ?
Daniel.
> -----Original Message-----
> From: Thomas Dudziak [mailto:tomdzk@gmail.com]
> Sent: 04 November 2005 17:26
> To: OJB Users List
> Subject: Re: PB linking problem
>
>
> On 11/4/05, Daniel Perry <d....@netcase.co.uk> wrote:
> > Not sure if this is really an bug, or just a 'feature', but
> things dont get
> > linked under certain curcumstances.
> >
> > I have two objects: activity, and attachment.
> >
> > An activity has a collection of attachments.
> >
> > /**
> > * @ojb.collection
> element-class-ref="com.netcase.pol.bo.Attachment"
> > * foreignkey="activityId"
> > *
> > query-customizer="com.netcase.ojb.NotDeletedQueryCustomizer"
> > * proxy="true" auto-retrieve="true"
> auto-update="object"
> > */
> > private List<Attachment> attachments;
> >
> > (attachment has: @ojb.field name="activityId" jdbc-type="INTEGER")
> >
> > The following works: (ie, activityId is set properly)
> > 1. persist an attachment.
> > 2. add it to the collection in activity.
> > 3. persist activity.
> >
> > However, if i add the following to attachment:
> > /**
> > * @ojb.reference foreignkey="activityId"
> > */
> > private Activity activity;
> >
> > then the above doesnt work. activityId ends up as 0. I guess i should
> > expect this as activity is null. But, still, as activity is
> being persisted
> > last, shouldnt it be updated for that link?
>
> I think you have to set the activity field in your code initially
> (before writing). OJB will initialize the field only when reading
> objects from the database (and it doesn't do so in between storing the
> collection and the reference).
>
> Tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: PB linking problem
Posted by Thomas Dudziak <to...@gmail.com>.
On 11/4/05, Daniel Perry <d....@netcase.co.uk> wrote:
> Not sure if this is really an bug, or just a 'feature', but things dont get
> linked under certain curcumstances.
>
> I have two objects: activity, and attachment.
>
> An activity has a collection of attachments.
>
> /**
> * @ojb.collection element-class-ref="com.netcase.pol.bo.Attachment"
> * foreignkey="activityId"
> *
> query-customizer="com.netcase.ojb.NotDeletedQueryCustomizer"
> * proxy="true" auto-retrieve="true" auto-update="object"
> */
> private List<Attachment> attachments;
>
> (attachment has: @ojb.field name="activityId" jdbc-type="INTEGER")
>
> The following works: (ie, activityId is set properly)
> 1. persist an attachment.
> 2. add it to the collection in activity.
> 3. persist activity.
>
> However, if i add the following to attachment:
> /**
> * @ojb.reference foreignkey="activityId"
> */
> private Activity activity;
>
> then the above doesnt work. activityId ends up as 0. I guess i should
> expect this as activity is null. But, still, as activity is being persisted
> last, shouldnt it be updated for that link?
I think you have to set the activity field in your code initially
(before writing). OJB will initialize the field only when reading
objects from the database (and it doesn't do so in between storing the
collection and the reference).
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org