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 Joerg Heinicke <jo...@gmx.de> on 2004/02/24 18:45:27 UTC

[OTM] can not delete from dependent collection

Hello,

I'm extending our application prototype more and more to test the OJB/OTM
features. It's nearly fun to just stay on the object level - OTM does the rest
for me. But now I came across a major and two minor problems:

1. The major one: I have an object 'Debitor' with a reference to an abstract
'Person' with a collection 'addresses'. Everything works wonderful besides the
deleting (and the first minor problem). I get an exception when an element from
the collection is missing and so should be deleted from the database:

org.apache.ojb.otm.core.TransactionAbortedException: markDelete failed: the
dependent object Address{22} is not in the editing context.

As I can not read more than "could not delete" from this error message I don't
know what's wrong and how to fix it. I also googled for this message and found
exactly one page: the commit of the corresponding code :-(

2. The first minor problem: The documentation on the repository.xml states more
than clearly that auto-update must be set to false if otm-dependent="true", OTM
would behave as the auto-update would be set to true then. My problem is that
this is neither correct nor working without auto-update="true".

It's about the same relation as above (person to addresses). If the auto-update
is not set to true, the foreign key column of Address named 'personId' is always
0. After adding auto-update="true" it works like expected.

3. The second minor problem: The above mentioned 'Debitor' can either be a
'NaturalPerson' or a 'LegalPerson', both extend the 'AbstractPerson', so
'Debitor' has a reference to 'AbstractPerson'. Though it might not be useful in
real life (will maybe be changed in the application, but it's helpful for
showing my problem) it's possible to switch between the both implementations.
The problem is that after the switch I have two 'AbstractPerson's in the
database, the new real one and the old one, that is definitely no longer used.
Maybe it's only a question of configuration but how can I delete the old
implementation of 'AbstractPerson' in the DB on update of 'Debitor'?

Below you will find the important parts of repository.xml and the Java classes.
I hope I have not oversimplified it. Of course every object has additionally a
primary key named 'id'.

Thanks for your help,

Joerg

public class Debitor {
    private AbstractPerson abstractPerson;
    private int abstractPersonId;
}

public abstract class AbstractPerson {
    protected Collection addresses;
}

public class Address {
    private int personId;
}

<class-descriptor class="com.ewerk.erak.model.AbstractPerson">
    <extent-class class-ref="com.ewerk.erak.model.LegalPerson"/>
    <extent-class class-ref="com.ewerk.erak.model.NaturalPerson"/>
</class-descriptor>

<class-descriptor class="com.ewerk.erak.model.Address" table="Address">
    <field-descriptor name="personId" column="personId" jdbc-type="INTEGER"/>
</class-descriptor>

<class-descriptor class="com.ewerk.erak.model.Debitor" table="Debitor">
    <field-descriptor name="abstractPersonId" column="abstractPersonId"
                      jdbc-type="INTEGER"/>
    <reference-descriptor name="abstractPerson"
                          class-ref="com.ewerk.erak.model.AbstractPerson"
                          otm-dependent="true">
        <foreignkey field-ref="abstractPersonId"/>
    </reference-descriptor>
</class-descriptor>

<class-descriptor class="com.ewerk.erak.model.LegalPerson" table="Person">
    <collection-descriptor name="addresses"
                           element-class-ref="com.ewerk.erak.model.Address"
                           auto-update="true" otm-dependent="true">
        <inverse-foreignkey field-ref="personId"/>
    </collection-descriptor>
</class-descriptor>

<class-descriptor class="com.ewerk.erak.model.NaturalPerson" table="Person">
    <collection-descriptor name="addresses"
                           element-class-ref="com.ewerk.erak.model.Address"
                           auto-update="true" otm-dependent="true">
        <inverse-foreignkey field-ref="personId"/>
    </collection-descriptor>
</class-descriptor>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [OTM] can not delete from dependent collection

Posted by Oleg Nitz <on...@ukr.net>.
Hello Joerg,

Thanks for the bug reports, I will try to prepare a junit test and 
then to make it run successfully :)

Regards,
 Oleg

On Tuesday 24 February 2004 17:45, Joerg Heinicke wrote:
> Hello,
>
> I'm extending our application prototype more and more to test the OJB/OTM
> features. It's nearly fun to just stay on the object level - OTM does the
> rest for me. But now I came across a major and two minor problems:
>
> 1. The major one: I have an object 'Debitor' with a reference to an
> abstract 'Person' with a collection 'addresses'. Everything works wonderful
> besides the deleting (and the first minor problem). I get an exception when
> an element from the collection is missing and so should be deleted from the
> database:
>
> org.apache.ojb.otm.core.TransactionAbortedException: markDelete failed: the
> dependent object Address{22} is not in the editing context.
>
> As I can not read more than "could not delete" from this error message I
> don't know what's wrong and how to fix it. I also googled for this message
> and found exactly one page: the commit of the corresponding code :-(
>
> 2. The first minor problem: The documentation on the repository.xml states
> more than clearly that auto-update must be set to false if
> otm-dependent="true", OTM would behave as the auto-update would be set to
> true then. My problem is that this is neither correct nor working without
> auto-update="true".
>
> It's about the same relation as above (person to addresses). If the
> auto-update is not set to true, the foreign key column of Address named
> 'personId' is always 0. After adding auto-update="true" it works like
> expected.
>
> 3. The second minor problem: The above mentioned 'Debitor' can either be a
> 'NaturalPerson' or a 'LegalPerson', both extend the 'AbstractPerson', so
> 'Debitor' has a reference to 'AbstractPerson'. Though it might not be
> useful in real life (will maybe be changed in the application, but it's
> helpful for showing my problem) it's possible to switch between the both
> implementations. The problem is that after the switch I have two
> 'AbstractPerson's in the database, the new real one and the old one, that
> is definitely no longer used. Maybe it's only a question of configuration
> but how can I delete the old implementation of 'AbstractPerson' in the DB
> on update of 'Debitor'?
>
> Below you will find the important parts of repository.xml and the Java
> classes. I hope I have not oversimplified it. Of course every object has
> additionally a primary key named 'id'.
>
> Thanks for your help,
>
> Joerg
>
> public class Debitor {
>     private AbstractPerson abstractPerson;
>     private int abstractPersonId;
> }
>
> public abstract class AbstractPerson {
>     protected Collection addresses;
> }
>
> public class Address {
>     private int personId;
> }
>
> <class-descriptor class="com.ewerk.erak.model.AbstractPerson">
>     <extent-class class-ref="com.ewerk.erak.model.LegalPerson"/>
>     <extent-class class-ref="com.ewerk.erak.model.NaturalPerson"/>
> </class-descriptor>
>
> <class-descriptor class="com.ewerk.erak.model.Address" table="Address">
>     <field-descriptor name="personId" column="personId"
> jdbc-type="INTEGER"/> </class-descriptor>
>
> <class-descriptor class="com.ewerk.erak.model.Debitor" table="Debitor">
>     <field-descriptor name="abstractPersonId" column="abstractPersonId"
>                       jdbc-type="INTEGER"/>
>     <reference-descriptor name="abstractPerson"
>                           class-ref="com.ewerk.erak.model.AbstractPerson"
>                           otm-dependent="true">
>         <foreignkey field-ref="abstractPersonId"/>
>     </reference-descriptor>
> </class-descriptor>
>
> <class-descriptor class="com.ewerk.erak.model.LegalPerson" table="Person">
>     <collection-descriptor name="addresses"
>                            element-class-ref="com.ewerk.erak.model.Address"
>                            auto-update="true" otm-dependent="true">
>         <inverse-foreignkey field-ref="personId"/>
>     </collection-descriptor>
> </class-descriptor>
>
> <class-descriptor class="com.ewerk.erak.model.NaturalPerson"
> table="Person"> <collection-descriptor name="addresses"
>                            element-class-ref="com.ewerk.erak.model.Address"
>                            auto-update="true" otm-dependent="true">
>         <inverse-foreignkey field-ref="personId"/>
>     </collection-descriptor>
> </class-descriptor>
>
>
> ---------------------------------------------------------------------
> 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: [OTM] can not delete from dependent collection

Posted by Joerg Heinicke <jo...@gmx.de>.
Oleg Nitz <on <at> ukr.net> writes:

> Hi Joerg,
> 
> I have fixed this issue too. You are extremely productive tester! 

Necessarily. We chose OTM for our application and I have to get it working.
Furthermore the good test covering of OJB helps much. We would be glad if we
were that good at Cocoon. And when you get everything fixed in hours/days it
makes nearly fun :)

> > My persons have a name, changing this one and making this change persistent
> > does not update the database. After makePersistent(debitor) it contains
> > again the original form, just like as it was not touched. The same happened
> > for me for the addresses, changes on them are not saved (both removing and
> > adding to an existing list and changing entries on a specific address). 

I'm quite happy at the moment. Thanks again.

Joerg


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [OTM] can not delete from dependent collection

Posted by Oleg Nitz <on...@ukr.net>.
Hi Joerg,

I have fixed this issue too. You are extremely productive tester! :-)

Oleg

On Tuesday 02 March 2004 16:39, Joerg Heinicke wrote:
> My persons have a name, changing this one and making this change persistent
> does not update the database. After makePersistent(debitor) it contains
> again the original form, just like as it was not touched. The same happened
> for me for the addresses, changes on them are not saved (both removing and
> adding to an existing list and changing entries on a specific address). 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [OTM] can not delete from dependent collection

Posted by Joerg Heinicke <jo...@gmx.de>.
Oleg Nitz <on <at> ukr.net> writes:

> 
> Hi Joerg,
> 
> I hope now issue 1 is solved too

Hello Oleg,

I really appreciate your efforts for helping me immediately.

After updating my OJB from CVS cascading create and cascading delete do work,
but unfortunately no longer cascading update that worked before:

My persons have a name, changing this one and making this change persistent does
not update the database. After makePersistent(debitor) it contains again the
original form, just like as it was not touched. The same happened for me for the
addresses, changes on them are not saved (both removing and adding to an
existing list and changing entries on a specific address). It seems to be still
an issue with the "long transaction" as removing the addresses inside the
transaction works (this was what the DependentTest tested).

This time my test patch is a bit longer. As I'm posting about gmane.org I can
not attach or zip it. Additionally gmane.org has an 80 character restriction and
few lines are longer than this. So I will sent the patch off the list. Maybe
it's just time to subscribe to the list :)

BTW, the target run-test should allow me to execute a specific test, doesn't it?
I tried it with -Dtest.package=org.apache.ojb.otm.AllTests and
org.apache.ojb.otm.DependentTests, but it fails because of a missing table
OTM_DEBITOR while it works with the target junit, but that's a bit time
consuming.

Sometimes I will be completely satisfied ;-)

Thanks again and regards,

Joerg


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [OTM] can not delete from dependent collection

Posted by Oleg Nitz <on...@ukr.net>.
Hi Joerg,

I hope now issue 1 is solved too ;-)

Regards,
 Oleg

On Monday 01 March 2004 14:17, Joerg Heinicke wrote:
> Oleg Nitz <on <at> ukr.net> writes:
> > Hi Joerg,
> >
> > I think I have solved all the problems that you mentioned, and even more
> > I confirm that otm-dependent="true" must be used with
> > auto-update="false". Thank you very must for the ideal bug report!
> >
> > Regards,
> >  Oleg
>
> Hello Oleg ... and also the other people,
>
> I have tested your new code and it would work nicely if I would not want to
> use it in another, maybe unexpected way :) The issues 2 and 3 are solved
> completely for me, but not issue 1. I'm using OJB in combination with
> Cocoon Forms framework aka Woody. Woody does the form binding to beans for
> me, at the end I only want to tell OJB that it should update a modified
> bean to the database, i.e. make the changes persistent.
>
> That means that I don't do (1) open tx, (2) change object, (3) commit tx,
> but (1)  change object, (2) open tx, (3) make changes persistent, (4)
> commit tx. Besides the deleting of objects this works wonderfully. If I
> really need to do the changes in a transaction, I need a second (in this
> case debitor) object just for setting all the changes. As it works for
> update without deleting in the expected way this would be somewhat
> inconsistent.
>
> Is the current behaviour now a bug or intended? For modifying the dependent
> test 2 I sent the patch to the test class below. With this change I can
> reproduce my behaviour.
>
> Regards,
>
> Joerg
>
> Index: src/test/org/apache/ojb/otm/DependentTests.java
> ===================================================================
> RCS file:
> /home/cvspublic/db-ojb/src/test/org/apache/ojb/otm/DependentTests.java,v
> retrieving revision 1.3
> diff -r1.3 DependentTests.java
> 180a181
>
> >         tx.commit();
>
> 183a185,188
>
> >         tx = _kit.getTransaction(_conn);
> >         tx.begin();
> >         _conn.makePersistent(debitor);
>
> 189a195
>
> >         assertTrue("person has correct type",
> > (debitor.getAbstractPerson()
>
> instanceof NaturalPerson));
>
>
>
> ---------------------------------------------------------------------
> 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: [OTM] can not delete from dependent collection

Posted by Joerg Heinicke <jo...@gmx.de>.
Oleg Nitz <on <at> ukr.net> writes:

> I am trying to support "long transactions" in OTM. I didn't keep them in mind 
> before, but now I realized that original Raghu design contains even a special 
> package - swizzling - which is a way of doing long transactions. 
> I.e. otmconn.makePersisntent() should work similar to broker.store(): 
> if exists then update, if doesn't exist then create. Of course, automatic 
> update of all changes and update via makePersisntent() are mutually 
> exclusive: only the object which was read inside transaction (say, via 
> getObjectByIdentity()) *is in transaction*. The object passed to 
> makePersisntent() is not included in the transaction (unless it is new), 
> it is just swizzled with transactional object (its fields values are copied to 
> the transactional object). 

Just curious: What does this mean for my latest issue report? Is it an issue in
OJB OTM or do I have to modify my code partly? And did you come across the
swizzle thing before or after patching the other issues :)

Not that I need it immediately, I have some else work to do on my project, but
of course updating objects is somewhat important to me :)

Joerg


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [OTM] can not delete from dependent collection

Posted by Oleg Nitz <on...@ukr.net>.
Hi Brian,

I am trying to support "long transactions" in OTM. I didn't keep them in mind 
before, but now I realized that original Raghu design contains even a special 
package - swizzling - which is a way of doing long transactions. 
I.e. otmconn.makePersisntent() should work similar to broker.store(): 
if exists then update, if doesn't exist then create. Of course, automatic 
update of all changes and update via makePersisntent() are mutually 
exclusive: only the object which was read inside transaction (say, via 
getObjectByIdentity()) *is in transaction*. The object passed to 
makePersisntent() is not included in the transaction (unless it is new), 
it is just swizzled with transactional object (its fields values are copied to 
the transactional object). 

Regards,
 Oleg

On Tuesday 02 March 2004 19:47, Brian McCallister wrote:
> I think Oleg made it safe to only fetch the master object. My
> particular example was where the Collection#remove(object) wasn't
> removing it as the object identity was different.
>
> I am pretty sure (Oleg will know better than me =) that you still need
> to obtain a reference to the parent object inside the bounds of the
> transaction.
>
> -Brian
>
> On Mar 2, 2004, at 1:28 PM, Joerg Heinicke wrote:
> > Brian McCallister <mccallister <at> forthillcompany.com> writes:
> >> Are you using an instance of the object obtained during a different
> >> transaction?
> >>
> >> for instance:
> >>
> >>      public void testRemoveChildren()
> >>      {
> >
> > [ ... store objects ... ]
> >
> >>          Transaction tx = kit.getTransaction(otmConnection);
> >>          tx.begin();
> >>          parent.removeChild(child2);
> >>          tx.commit();
> >
> > [ ... asserts ... ]
> >
> >>      }
> >>
> >> Will fail
> >>
> >>      public void testRemoveChildren()
> >>      {
> >
> > [ ... store objects ... ]
> >
> >>          Transaction tx = kit.getTransaction(otmConnection);
> >>          tx.begin();
> >>          parent = (Parent)
> >> otmConnection.getObjectByIdentity(otmConnection.getIdentity(parent));
> >>          child2 = (Child)
> >> otmConnection.getObjectByIdentity(otmConnection.getIdentity(child2));
> >>          parent.removeChild(child2);
> >>          tx.commit();
> >
> > [ ... asserts ... ]
> >
> >>      }
> >>
> >> Will pass. The objects need to be bound to the current tx.
> >>
> >> where store begins a transaction, stores, and then commits the
> >> transaction.
> >>
> >> -Brian
> >
> > Hello Brian,
> >
> > I don't know if I understand you correctly as the above seems to be
> > contradicting to Oleg's patches. The recent version of DependentTests
> > reflects
> > my wishes at best I guess [1]. I want to modify the objects outside of
> > any
> > transaction (Cocoon Forms/Woody does it for me) and make the changes
> > persistent
> > afterwards (the obects are given back to the data access layer). Of
> > course it's
> > possible that I need better identity handling to delete/update
> > correctly my
> > objects and its dependencies in my application. For that reason I used
> > the OJB
> > tests to show the effects I have and until now I could reproduce my
> > problems
> > there. If you think the current version of DependentTests is invalid
> > please tell
> > me - maybe Oleg has already to much fixed then.
> >
> > Joerg
> >
> > [1]
> > http://cvs.apache.org/viewcvs.cgi/db-ojb/src/test/org/apache/ojb/otm/
> > DependentTests.java?rev=1.4&view=markup
> >
> >
> > ---------------------------------------------------------------------
> > 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: [OTM] can not delete from dependent collection

Posted by Brian McCallister <mc...@forthillcompany.com>.
I think Oleg made it safe to only fetch the master object. My 
particular example was where the Collection#remove(object) wasn't 
removing it as the object identity was different.

I am pretty sure (Oleg will know better than me =) that you still need 
to obtain a reference to the parent object inside the bounds of the 
transaction.

-Brian

On Mar 2, 2004, at 1:28 PM, Joerg Heinicke wrote:

> Brian McCallister <mccallister <at> forthillcompany.com> writes:
>
>> Are you using an instance of the object obtained during a different
>> transaction?
>>
>> for instance:
>>
>>      public void testRemoveChildren()
>>      {
>
> [ ... store objects ... ]
>
>>          Transaction tx = kit.getTransaction(otmConnection);
>>          tx.begin();
>>          parent.removeChild(child2);
>>          tx.commit();
>
> [ ... asserts ... ]
>
>>      }
>>
>> Will fail
>>
>>      public void testRemoveChildren()
>>      {
>
> [ ... store objects ... ]
>
>>          Transaction tx = kit.getTransaction(otmConnection);
>>          tx.begin();
>>          parent = (Parent)
>> otmConnection.getObjectByIdentity(otmConnection.getIdentity(parent));
>>          child2 = (Child)
>> otmConnection.getObjectByIdentity(otmConnection.getIdentity(child2));
>>          parent.removeChild(child2);
>>          tx.commit();
>
> [ ... asserts ... ]
>
>>      }
>>
>> Will pass. The objects need to be bound to the current tx.
>>
>> where store begins a transaction, stores, and then commits the
>> transaction.
>>
>> -Brian
>
> Hello Brian,
>
> I don't know if I understand you correctly as the above seems to be
> contradicting to Oleg's patches. The recent version of DependentTests 
> reflects
> my wishes at best I guess [1]. I want to modify the objects outside of 
> any
> transaction (Cocoon Forms/Woody does it for me) and make the changes 
> persistent
> afterwards (the obects are given back to the data access layer). Of 
> course it's
> possible that I need better identity handling to delete/update 
> correctly my
> objects and its dependencies in my application. For that reason I used 
> the OJB
> tests to show the effects I have and until now I could reproduce my 
> problems
> there. If you think the current version of DependentTests is invalid 
> please tell
> me - maybe Oleg has already to much fixed then.
>
> Joerg
>
> [1] 
> http://cvs.apache.org/viewcvs.cgi/db-ojb/src/test/org/apache/ojb/otm/
> DependentTests.java?rev=1.4&view=markup
>
>
> ---------------------------------------------------------------------
> 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: [OTM] can not delete from dependent collection

Posted by Joerg Heinicke <jo...@gmx.de>.
Brian McCallister <mccallister <at> forthillcompany.com> writes:

> Are you using an instance of the object obtained during a different  
> transaction?
> 
> for instance:
> 
>      public void testRemoveChildren()
>      {

[ ... store objects ... ]

>          Transaction tx = kit.getTransaction(otmConnection);
>          tx.begin();
>          parent.removeChild(child2);
>          tx.commit();

[ ... asserts ... ]

>      }
> 
> Will fail
> 
>      public void testRemoveChildren()
>      {

[ ... store objects ... ]

>          Transaction tx = kit.getTransaction(otmConnection);
>          tx.begin();
>          parent = (Parent)  
> otmConnection.getObjectByIdentity(otmConnection.getIdentity(parent));
>          child2 = (Child)  
> otmConnection.getObjectByIdentity(otmConnection.getIdentity(child2));
>          parent.removeChild(child2);
>          tx.commit();

[ ... asserts ... ]

>      }
> 
> Will pass. The objects need to be bound to the current tx.
> 
> where store begins a transaction, stores, and then commits the  
> transaction.
> 
> -Brian

Hello Brian,

I don't know if I understand you correctly as the above seems to be
contradicting to Oleg's patches. The recent version of DependentTests reflects
my wishes at best I guess [1]. I want to modify the objects outside of any
transaction (Cocoon Forms/Woody does it for me) and make the changes persistent
afterwards (the obects are given back to the data access layer). Of course it's
possible that I need better identity handling to delete/update correctly my
objects and its dependencies in my application. For that reason I used the OJB
tests to show the effects I have and until now I could reproduce my problems
there. If you think the current version of DependentTests is invalid please tell
me - maybe Oleg has already to much fixed then.

Joerg

[1] http://cvs.apache.org/viewcvs.cgi/db-ojb/src/test/org/apache/ojb/otm/
DependentTests.java?rev=1.4&view=markup


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [OTM] can not delete from dependent collection

Posted by Brian McCallister <mc...@forthillcompany.com>.
Joerg,

Are you using an instance of the object obtained during a different  
transaction?

for instance:

     public void testRemoveChildren() throws LockingException,  
LookupException, SQLException
     {
         Parent parent = new Parent("The Parent");
         Child child1 = new Child(parent, "George");
         Child child2 = new Child(parent, "Frank");

         store(parent);

         Transaction tx = kit.getTransaction(otmConnection);
         tx.begin();
         parent.removeChild(child2);
         tx.commit();

         assertEquals(1, countRowsInTable("Parent"));
         assertEquals(1, countRowsInTable("Child"));
     }

Will fail

     public void testRemoveChildren() throws LockingException,  
LookupException, SQLException
     {
         Parent parent = new Parent("The Parent");
         Child child1 = new Child(parent, "George");
         Child child2 = new Child(parent, "Frank");

         store(parent);

         Transaction tx = kit.getTransaction(otmConnection);
         tx.begin();
         parent = (Parent)  
otmConnection.getObjectByIdentity(otmConnection.getIdentity(parent));
         child2 = (Child)  
otmConnection.getObjectByIdentity(otmConnection.getIdentity(child2));
         parent.removeChild(child2);
         tx.commit();

         assertEquals(1, countRowsInTable("Parent"));
         assertEquals(1, countRowsInTable("Child"));
     }

Will pass. The objects need to be bound to the current tx.

where store begins a transaction, stores, and then commits the  
transaction.

-Brian

On Mar 1, 2004, at 9:17 AM, Joerg Heinicke wrote:

> Oleg Nitz <on <at> ukr.net> writes:
>
>> Hi Joerg,
>>
>> I think I have solved all the problems that you mentioned, and even  
>> more
>> I confirm that otm-dependent="true" must be used with  
>> auto-update="false".
>> Thank you very must for the ideal bug report!
>>
>> Regards,
>>  Oleg
>
> Hello Oleg ... and also the other people,
>
> I have tested your new code and it would work nicely if I would not  
> want to use
> it in another, maybe unexpected way :) The issues 2 and 3 are solved  
> completely
> for me, but not issue 1. I'm using OJB in combination with Cocoon Forms
> framework aka Woody. Woody does the form binding to beans for me, at  
> the end I
> only want to tell OJB that it should update a modified bean to the  
> database,
> i.e. make the changes persistent.
>
> That means that I don't do (1) open tx, (2) change object, (3) commit  
> tx, but
> (1)  change object, (2) open tx, (3) make changes persistent, (4)  
> commit tx.
> Besides the deleting of objects this works wonderfully. If I really  
> need to do
> the changes in a transaction, I need a second (in this case debitor)  
> object just
> for setting all the changes. As it works for update without deleting  
> in the
> expected way this would be somewhat inconsistent.
>
> Is the current behaviour now a bug or intended? For modifying the  
> dependent test
> 2 I sent the patch to the test class below. With this change I can  
> reproduce my
> behaviour.
>
> Regards,
>
> Joerg
>
> Index: src/test/org/apache/ojb/otm/DependentTests.java
> ===================================================================
> RCS file:
> /home/cvspublic/db-ojb/src/test/org/apache/ojb/otm/ 
> DependentTests.java,v
> retrieving revision 1.3
> diff -r1.3 DependentTests.java
> 180a181
>>         tx.commit();
> 183a185,188
>>
>>         tx = _kit.getTransaction(_conn);
>>         tx.begin();
>>         _conn.makePersistent(debitor);
> 189a195
>>         assertTrue("person has correct type",  
>> (debitor.getAbstractPerson()
> instanceof NaturalPerson));
>
>
>
> ---------------------------------------------------------------------
> 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: [OTM] can not delete from dependent collection

Posted by Joerg Heinicke <jo...@gmx.de>.
Oleg Nitz <on <at> ukr.net> writes:

> Hi Joerg,
> 
> I think I have solved all the problems that you mentioned, and even more 
> I confirm that otm-dependent="true" must be used with auto-update="false".
> Thank you very must for the ideal bug report! 
> 
> Regards,
>  Oleg

Hello Oleg ... and also the other people,

I have tested your new code and it would work nicely if I would not want to use
it in another, maybe unexpected way :) The issues 2 and 3 are solved completely
for me, but not issue 1. I'm using OJB in combination with Cocoon Forms
framework aka Woody. Woody does the form binding to beans for me, at the end I
only want to tell OJB that it should update a modified bean to the database,
i.e. make the changes persistent.

That means that I don't do (1) open tx, (2) change object, (3) commit tx, but
(1)  change object, (2) open tx, (3) make changes persistent, (4) commit tx.
Besides the deleting of objects this works wonderfully. If I really need to do
the changes in a transaction, I need a second (in this case debitor) object just
for setting all the changes. As it works for update without deleting in the
expected way this would be somewhat inconsistent.

Is the current behaviour now a bug or intended? For modifying the dependent test
2 I sent the patch to the test class below. With this change I can reproduce my
behaviour.

Regards,

Joerg

Index: src/test/org/apache/ojb/otm/DependentTests.java
===================================================================
RCS file:
/home/cvspublic/db-ojb/src/test/org/apache/ojb/otm/DependentTests.java,v
retrieving revision 1.3
diff -r1.3 DependentTests.java
180a181
>         tx.commit();
183a185,188
>
>         tx = _kit.getTransaction(_conn);
>         tx.begin();
>         _conn.makePersistent(debitor);
189a195
>         assertTrue("person has correct type", (debitor.getAbstractPerson()
instanceof NaturalPerson));



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [OTM] can not delete from dependent collection

Posted by Oleg Nitz <on...@ukr.net>.
Hi Joerg,

I think I have solved all the problems that you mentioned, and even more ;-)
I confirm that otm-dependent="true" must be used with auto-update="false".
Thank you very must for the ideal bug report! :-)

Regards,
 Oleg

On Tuesday 24 February 2004 17:45, Joerg Heinicke wrote:
> Hello,
>
> I'm extending our application prototype more and more to test the OJB/OTM
> features. It's nearly fun to just stay on the object level - OTM does the
> rest for me. But now I came across a major and two minor problems:
>
> 1. The major one: I have an object 'Debitor' with a reference to an
> abstract 'Person' with a collection 'addresses'. Everything works wonderful
> besides the deleting (and the first minor problem). I get an exception when
> an element from the collection is missing and so should be deleted from the
> database:
>
> org.apache.ojb.otm.core.TransactionAbortedException: markDelete failed: the
> dependent object Address{22} is not in the editing context.
>
> As I can not read more than "could not delete" from this error message I
> don't know what's wrong and how to fix it. I also googled for this message
> and found exactly one page: the commit of the corresponding code :-(
>
> 2. The first minor problem: The documentation on the repository.xml states
> more than clearly that auto-update must be set to false if
> otm-dependent="true", OTM would behave as the auto-update would be set to
> true then. My problem is that this is neither correct nor working without
> auto-update="true".
>
> It's about the same relation as above (person to addresses). If the
> auto-update is not set to true, the foreign key column of Address named
> 'personId' is always 0. After adding auto-update="true" it works like
> expected.
>
> 3. The second minor problem: The above mentioned 'Debitor' can either be a
> 'NaturalPerson' or a 'LegalPerson', both extend the 'AbstractPerson', so
> 'Debitor' has a reference to 'AbstractPerson'. Though it might not be
> useful in real life (will maybe be changed in the application, but it's
> helpful for showing my problem) it's possible to switch between the both
> implementations. The problem is that after the switch I have two
> 'AbstractPerson's in the database, the new real one and the old one, that
> is definitely no longer used. Maybe it's only a question of configuration
> but how can I delete the old implementation of 'AbstractPerson' in the DB
> on update of 'Debitor'?
>
> Below you will find the important parts of repository.xml and the Java
> classes. I hope I have not oversimplified it. Of course every object has
> additionally a primary key named 'id'.
>
> Thanks for your help,
>
> Joerg
>
> public class Debitor {
>     private AbstractPerson abstractPerson;
>     private int abstractPersonId;
> }
>
> public abstract class AbstractPerson {
>     protected Collection addresses;
> }
>
> public class Address {
>     private int personId;
> }
>
> <class-descriptor class="com.ewerk.erak.model.AbstractPerson">
>     <extent-class class-ref="com.ewerk.erak.model.LegalPerson"/>
>     <extent-class class-ref="com.ewerk.erak.model.NaturalPerson"/>
> </class-descriptor>
>
> <class-descriptor class="com.ewerk.erak.model.Address" table="Address">
>     <field-descriptor name="personId" column="personId"
> jdbc-type="INTEGER"/> </class-descriptor>
>
> <class-descriptor class="com.ewerk.erak.model.Debitor" table="Debitor">
>     <field-descriptor name="abstractPersonId" column="abstractPersonId"
>                       jdbc-type="INTEGER"/>
>     <reference-descriptor name="abstractPerson"
>                           class-ref="com.ewerk.erak.model.AbstractPerson"
>                           otm-dependent="true">
>         <foreignkey field-ref="abstractPersonId"/>
>     </reference-descriptor>
> </class-descriptor>
>
> <class-descriptor class="com.ewerk.erak.model.LegalPerson" table="Person">
>     <collection-descriptor name="addresses"
>                            element-class-ref="com.ewerk.erak.model.Address"
>                            auto-update="true" otm-dependent="true">
>         <inverse-foreignkey field-ref="personId"/>
>     </collection-descriptor>
> </class-descriptor>
>
> <class-descriptor class="com.ewerk.erak.model.NaturalPerson"
> table="Person"> <collection-descriptor name="addresses"
>                            element-class-ref="com.ewerk.erak.model.Address"
>                            auto-update="true" otm-dependent="true">
>         <inverse-foreignkey field-ref="personId"/>
>     </collection-descriptor>
> </class-descriptor>
>
>
> ---------------------------------------------------------------------
> 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