<<one2many-Sample.zip>>
 
Hi,
 
I am using Castor 0.9.4 and testing a one-to-many case. I found the result is wrong. The value of the foreign key (for the "many") is not written to the database.  I have attached the source code including DB script, mapping.xml to this mail.
 
I paste some parts here for a quick look:
 
**************************************************
The result:
 
a) Table "worker"
id, firstname, lastname, date_of_birth
------------------------------
1, Jason, Mchuge, 01/01/70
 
b) Table "tasks"
 
id, description, worker_id
------------------------
1, Task1, null
2, Task2, null
3, Task3, null
 
**************************************************
 
As you see nothing is written to the "worker_id" field.
 
 
 
 
-- ====================================
--  One to many
-- ====================================
 
create table worker
(
    id integer not null,
    firstname varchar(40) not null,
    lastname varchar(40) not null,
    date_of_birth date,
    primary key (id)
);
 
create table task
(
   id integer not null,
   description varchar(255),
   worker_id integer references worker(id),
   primary key (id)
);
 
   <-- the mapping -->
 
    <!-- each worker has many tasks-->
    <field name="tasks" type="sample.imtf.ch.atlas.pollux.jdo.one2many.Task"
            collection="arraylist"
            required="false"
            set-method="setTasks" get-method="getTasks">
        <sql many-key="worker_id"/>
    </field>
 
/**
The main program
*/
        aDb.begin();
 
        Task task1 = new Task(1, "Task1");
        Task task2 = new Task(2, "Task2");
        Task task3 = new Task(3, "Task3");
        aDb.create(task1);
        aDb.create(task2);
        aDb.create(task3);
 
        Worker worker = new Worker();
        worker.setId(1);
        worker.setFirstname("Jason");
        worker.setLastname("McHuge");
        worker.setDate_of_birth(new Date(0));
 
        worker.addTask(task1);
        worker.addTask(task2);
        worker.addTask(task3);

        aDb.create(worker);

        aDb.commit();
 
 
Could anyone help me?
 
Thanks in advance.
 
Albert

Attachment: one2many-Sample.zip
Description: Zip compressed data

Reply via email to