This is really driving me nuts now. I'm trying to get a course:lessons
mapping to work. The config is:

<!-- COURSE -->
<class-descriptor class="com.mp.hato.ojb.OJBCourse" proxy="dynamic"
table="courses">
    <field-descriptor name="id" column="course_id" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
    <field-descriptor name="name" column="courseName"
jdbc-type="VARCHAR"/>
    <field-descriptor name="number" column="courseNumber"
jdbc-type="INTEGER"/>
    
    <collection-descriptor name="lessons"
collection-class="org.apache.ojb.broker.util.collections.ManageableVector"
element-class-ref="com.mp.hato.ojb.OJBLesson" auto-delete="false"
auto-update="false" auto-retrieve="true"
indirection-table="course_lesson">
        <fk-pointing-to-this-class column="course"/>
        <fk-pointing-to-element-class column="lesson"/>
    </collection-descriptor>
</class-descriptor>

<!-- LESSON -->
<class-descriptor class="com.mp.hato.ojb.OJBLesson" proxy="dynamic"
table="lessons">
    <field-descriptor name="id" column="lesson_id" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
    <field-descriptor name="name" column="lessonName"
jdbc-type="VARCHAR"/>
    <field-descriptor name="number" column="lessonNumber"
jdbc-type="INTEGER"/>

    <collection-descriptor name="courses"
collection-class="org.apache.ojb.broker.util.collections.ManageableVector"
element-class-ref="com.mp.hato.ojb.OJBCourse" auto-delete="false"
auto-update="false" auto-retrieve="true"
indirection-table="course_lesson">
        <fk-pointing-to-this-class column="lesson"/>
        <fk-pointing-to-element-class column="course"/>
    </collection-descriptor>
</class-descriptor>

and the test method:

Implementation odmg = OJB.getInstance();
            Database db = odmg.newDatabase();
            db.open("default", Database.OPEN_READ_WRITE);

            TransactionExt tx = (TransactionExt)
odmg.newTransaction();
            tx.begin();
            
            OQLQuery query = odmg.newOQLQuery();
            query.create("select ojbs from com.mp.hato.ojb.OJBCourse
where id=$1");
            query.bind(new Integer(1));
            List results = (List) query.execute();
            
            Course course = (Course) results.iterator().next();
            
            List lessons = course.getLessons();
            
            Iterator i = lessons.iterator();            
            Lesson lesson = (Lesson) i.next();
            System.out.println("Removing lesson " + lesson.getId() + "
(" + lesson.getName() + ")");
            lessons.remove(lesson);
            tx.commit();
            
            db.close();

I have a single course (id=1) and two lessons (ids 1 and 21). Before
running the method, The indirection table links the course to both
lessons.
I run it, and get the output "Removing lesson 21 (Test)"
When I have a look at the indirection table, it now contains two links
from the course to lesson 21. So not only has it deleted the link to the
other lesson, but
its added an extra link to the lesson I asked it to delete.

Obviously I'm making a huge mistake somewhere, but I can't see
what....

Keith

>>> [EMAIL PROTECTED] 04/05/04 02:43PM >>>
I've been trying to get this working all morning, with many varied
(and
occasionally amusing)  results, but nothing quite right. Could someone
let me know how to do the following (sample config xml and any
relevent
code would be great!)

I have two objects in a m:n relationship, eg project and user. There
is
an ojb managed indirection table. I'd like to be able to make a call
like
aProject.getUsers().remove(aUser)
And have it delete just the aUser/aProject entry in the indirection
table.

Also, am I able to delete a user, using the db.deletePersistent(aUser)
method, and have it delete the user and all the user's entries in the
inderection table, and nothing else?  (and vice versa, deleting a
project)

Thanks in advance for any help on this

Keith


The information in this e-mail is confidential and intended to be
solely for the use of the addressee(s) and may contain copyright and/or
legally privileged information.  If you are not the addressee (or
responsible for delivery of the message to the addressee) please e-mail
us at [EMAIL PROTECTED] and delete the message from your
computer; copying, distribution, use or disclosure of its contents is
strictly prohibited.
As Internet communications are capable of data corruption no
responsibility is accepted for changes made to this message after it was
sent. For this reason it may be inappropriate to rely on advice
contained in any e-mail without obtaining written confirmation of it.
In addition, no liability or responsibility is accepted for viruses and
it is your responsibility to scan attachments (if any).
Please note that for business purposes, outgoing and incoming emails
from and to the company may be monitored and recorded.

Mouchel Parkman UK Ltd, Registered in England at West Hall, Parvis
Road, West Byfleet, Surrey UK KT14 6EZ Registered No : 1686040


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



The information in this e-mail is confidential and intended to be solely for the use 
of the addressee(s) and may contain copyright and/or legally privileged information.  
If you are not the addressee (or responsible for delivery of the message to the 
addressee) please e-mail us at [EMAIL PROTECTED] and delete the message from your 
computer; copying, distribution, use or disclosure of its contents is strictly 
prohibited.
As Internet communications are capable of data corruption no responsibility is 
accepted for changes made to this message after it was sent. For this reason it may be 
inappropriate to rely on advice contained in any e-mail without obtaining written 
confirmation of it.
In addition, no liability or responsibility is accepted for viruses and it is your 
responsibility to scan attachments (if any).
Please note that for business purposes, outgoing and incoming emails from and to the 
company may be monitored and recorded.

Mouchel Parkman UK Ltd, Registered in England at West Hall, Parvis Road, West Byfleet, 
Surrey UK KT14 6EZ Registered No : 1686040


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

Reply via email to