Hello
I'm using the ODMG API and I have two tables (Semester and CourseGroup)
with a m:n relationship. I set up the repository.xml and the database
tables as mentioned in the documentation. The following code should
result in a CourseGroup with a collection of the Semesters 6 and 7. At
this moments the Semesters exist already but shall be updated. But
instead the second codeblock is overwriting the first one. The result is
that the Semester collection of CourseGroup has just got the last
updated Semester number 7...
What I'm doing wrong?
Please help me, I'm desperate and I was trying things out the whole night.
Thanks in advance
/Olaf
public class DBTool
{
...
s = (Semester)querySelectFirst(Semester.class, "number=6");
cg = (CourseGroup)querySelectFirst(CourseGroup.class, "hours=8");
tx = odmg.newTransaction();
tx.begin();
tx.lock(s, tx.WRITE);
s.getCollCourseGroup().add(cg);
tx.commit();
s = (Semester)querySelectFirst(Semester.class, "number=7");
cg = (CourseGroup)querySelectFirst(CourseGroup.class, "hours=8");
tx = odmg.newTransaction();
tx.begin();
tx.lock(s, tx.WRITE);
s.getCollCourseGroup().add(cg);
tx.commit();
...
public Object querySelectFirst(Class clazz, String whereClause)
throws Exception {
Transaction tx = odmg.newTransaction();
tx.begin();
String where = null;
if(whereClause.length() == 0) {
where = "";
}else{
where=" where "+whereClause;
}
OQLQuery query = odmg.newOQLQuery();
query.create("select x from " + clazz.getName()+where);
DList dl = (DList)query.execute();
tx.commit();
if(dl.isEmpty()) throw new Exception("querySelect: Query has no
results");
return dl.get(0);
}
}
repository.xml (In the docs it was once said that the auto-xxx options
should all be to default when using ODMG, but here it isn't - is that
correct?)
...
<collection-descriptor
name="collCourseGroup"
element-class-ref="og.timetable.persistent.CourseGroup"
auto-retrieve="true"
auto-update="true"
auto-delete="false"
indirection-table="SEMESTER_COURSEGROUP"
>
<fk-pointing-to-this-class column="SEMESTER_ID"/>
<fk-pointing-to-element-class column="COURSEGROUP_ID"/>
</collection-descriptor>
...
<collection-descriptor
name="collSemester"
element-class-ref="og.timetable.persistent.Semester"
auto-retrieve="true"
auto-update="true"
auto-delete="false"
indirection-table="SEMESTER_COURSEGROUP"
>
<fk-pointing-to-this-class column="COURSEGROUP_ID"/>
<fk-pointing-to-element-class column="SEMESTER_ID"/>
</collection-descriptor>
SQL:
CREATE TABLE Semester_CourseGroup (
Semester_id INTEGER NOT NULL,
CourseGroup_id INTEGER NOT NULL,
PRIMARY KEY (Semester_id, CourseGroup_id),
FOREIGN KEY (Semester_id)
REFERENCES Semester
FOREIGN KEY (Curriculum_id)
REFERENCES Curriculum
);
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>