You will need to manage the cache by yourself if you use the PersistenceBroker API. 

In my project we have actually created two "helper methods" for this purpose,
one is appropriately called "link" and the other "unlink". 
They are not in the OJB distribution, but easy to make yourself. 

These methods will take 3 or 4 parameters: 
the "parent" object, the name of the collection or reference field, the "child" object,
and optionally the name of the inverse reference field. It can work for both 
collections
and references and inverse references, with some simple instanceof(Collection) checks
for example. The method will have to update the collection or reference by adding or
removing references, and also do that to the inverse reference. If needed it will
also store the object to the database (using persistenceBroker), and maintain the 
cache. 
That way object integrity will be maintained, and you will become less paranoid. 

I think one has to keep in mind that OJB is a persistence engine, it does not "own" 
all your
Java objects. First you change the relationships in your Javaobjects, and then you 
persist
the affected objects to the database (and them make sure that the cache gets updated). 

Just my two cents,
        Theo Niemeijer. 



> -----Oorspronkelijk bericht-----
> Van: Denis Avdic [mailto:[EMAIL PROTECTED]
> Verzonden: dinsdag 3 juni 2003 21:34
> Aan: OJB Users List
> Onderwerp: Re: [Newbie] deleting objects in inverse relationship
> 
> 
> No takers on this?
> I could not find anything in the docs to answer this question, that is 
> why i turned here.  Anyone?
> 
> Denis Avdic wrote:
> 
> > Hello,
> >
> > I have a small problem and I was wondering if anyone on this list 
> > would know the answer...
> >
> > I have a relatively simple database and I have a couple of inverse 
> > foreign key relationship between some objects.
> >
> > In my "parent" object I have
> >
> >    <collection-descriptor
> >            name="responses"
> >            element-class-ref="com.blah.blah.beans.Response"
> >            auto-retrieve="true"
> >            auto-update="true"
> >            auto-delete="true"
> >        >
> >            <inverse-foreignkey field-ref="submissionId"/>
> >        </collection-descriptor>
> >
> >
> > I am using the PersistenceBroker interface and when I need to delete a 
> > response I delete it with:
> >
> >            Criteria c = null;
> >            Query q = null;
> >                      for (int i = 0; i < out.size(); i++) {
> >                              Response temp = (Response) out.get(i);
> >
> >                c = new Criteria();
> >                c.addEqualTo("id", Integer.toString(temp.getId()));
> >                q = new QueryByCriteria(Response.class, c);
> >                              broker.deleteByQuery(q);             }
> >
> > Now, the response is deleted from the database (I checked).  However, 
> > when I try to access the page again, it displays the responses there 
> > (since I retrieve my submissions and I take all the responses 
> > retrieved with the submissions).  So, I am not sure how to avoid this 
> > behavior.  I need to retrieve by submission, not by response, so is 
> > there a way to update (I presume) the cache to  reflect the changed DB 
> > state?
> >
> > Thanks,
> >
> > Denis
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to