Hi I've got the following table
CREATE TABLE expenses(
id serial NOT NULL PRIMARY KEY,
fk_employeeid int4 NOT NULL,
fk_projectid int4 NOT NULL,
expensedate date NOT NULL,
fk_expensetype int4 NOT NULL,
notice varchar(2000) NOT NULL,
numberofkm numeric,
hours numeric,
amount numeric,
invoicable numeric(1),
invoiced numeric(1),
responsible int4 NOT NULL,
FOREIGN KEY (fk_employeeid) REFERENCES employees (id),
FOREIGN KEY (fk_projectid) REFERENCES projects (id),
FOREIGN KEY (fk_expensetype) REFERENCES expensetypes (id),
FOREIGN KEY (responsible) REFERENCES employees (id));
What I do:
I create a new Expenses object and register it with DataContext:
Expenses newexpensesentry =
(Expenses)theDataContext.createAndRegisterNewObject("Expenses");
then I fill all the values into that object I've defined relations for
the fk_.. references
<obj-relationship name="ToEmployees" source="Expenses"
target="Employees" toMany="false">
<db-relationship-ref source="expenses" target="employees"
name="ToEmployees"/>
</obj-relationship>
<obj-relationship name="ToEmployeesResponsible" source="Expenses"
target="Employees" toMany="false">
<db-relationship-ref source="expenses" target="employees"
name="ToEmployeesResponsible"/>
</obj-relationship>
<obj-relationship name="ToExpensetype" source="Expenses"
target="Expensetypes" toMany="false">
<db-relationship-ref source="expenses" target="expensetypes"
name="ToExpensetype"/>
</obj-relationship>
<obj-relationship name="ToProjects" source="Expenses" target="Projects"
toMany="false">
<db-relationship-ref source="expenses" target="projects"
name="ToProjects"/>
</obj-relationship>
then I set the refenrenced objects i.e.
newexpensesentry.ToExpensetype((Expensetypes)theDataContext.registeredObject(new
ObjectId(Expensetypes.class, "id",new Integer(1)))));
I have the find the referenced object via it's primary key because from
a web-interface I only get the primary key for the referenced object and
not the object itself
I do this for all the referenced objects:
then I call theDataContext.commitChanges(Level.WARN);
everything works fine, the problem comes now:
If I get a list of expenses in a timerange (the Expense object inserted
above is under the returned objects), then the newly created Expense
objects I get in return from my query has an empty (properties are
empty) Projects (relation ToProjects) objects related to it. The strange
thing is, that the ExpenseType object that I get over the relation
ToExpensetype is ok.
If I create a NEW DataContext and rerun the query, again, everything is
ok, also the Projects object thas had empty properties before.
If I use THE SAME DataContext to insert a new Espense object and the run
the query I get problems as described above.
Has anyone a idea what the problem could be here?
thanks in advance
martin
This archive was generated by hypermail 2.0.0 : Thu Dec 12 2002 - 13:03:06 EST