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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to