I am new to OQL, so if some could enlighten me I would appreciate it.

I have two objects (Course, Category) they have a many-to-many relationship.

I am trying to find a Category by its code (which executes fine).   Then I
want to find
all Course(s) that relate to the just found Category and also have some
other constraints.

Here are my OQLQuery(s) for the description above:

    OQLQuery query = db.getOQLQuery( "SELECT c FROM Category c WHERE name =
$1" );

    OQLQuery query2 = db.getOQLQuery( 
                "SELECT c FROM Course c WHERE categories = $1 AND program =
$2 AND status = $3" );

Here is my mapping file:

<mapping>

    <!-- Mapping for Category -->
    <class name="Category" identity="code"> 
        <description>Category for Courses</description>
        <map-to table="CATEGORY" xml="category"/>
        <field name="code" type="integer">
            <sql name="cat_code" type="integer"/>
            <xml name="code" node="attribute"/>
        </field>
        <field name="name" type="string">
            <sql name="category" type="char"/>
            <xml name="name" node="element"/>
        </field>
        <field name="comment" type="string">
            <sql name="comment" type="char"/>
            <xml name="comment" node="element"/>
        </field>
        <field name="courses" type="Course" collection="set">
            <sql name="course_code" many-table="COURSE_CATEGORY"
many-key="cat_code"/>
            <xml name="courses" node="element"/>
        </field>
    </class>

    <class name="Course" identity="code" access="read-only">
        <description>Course</description>
        <map-to table="COURSE" xml="course"/>
        <field name="code" type="string">
            <sql name="course_code" type="char"/>
            <xml name="code" node="element"/>
        </field>
        <field name="name" type="string">
            <sql name="course_name" type="char"/>
            <xml name="name" node="element"/>
        </field>
        <field name="program" type="string">
            <sql name="program_code" type="char"/>
            <xml name="program" node="element"/>
        </field>
        <field name="description" type="string">
            <sql name="descr" type="char"/>
            <xml name="description" node="element"/>
        </field>
        <field name="status" type="string">
            <sql name="status" type="char"/>
            <xml name="status" node="element"/>
        </field>
        <field name="comment" type="string">
            <sql name="comment" type="char"/>
            <xml name="comment" node="element"/>
        </field>
        <field name="categories" type="Category" collection="set">
            <sql name="cat_code" many-table="COURSE_CATEGORY"
many-key="course_code"/>
            <xml name="categories" node="element"/>
        </field>
    </class>

</mapping>

Here is the error that I am getting.   It seems as though it is trying to
access the many-key on the Course table (COURSE).   It seems like if you are
executing a query on the many table, then it should use the many_table.   Is
this some sort of bug?   I think that the last line is the query that was
generated by my last OQLQuery statement.   Sorry the output is a little
sloppy.  I am using ANT.

     [java] [test] SQL for creating Category: INSERT INTO "CATEGORY"
("cat_code","category","comment
") VALUES (?,?,?)
     [java] [test] SQL for deleting Category: DELETE FROM "CATEGORY" WHERE
"cat_code"=?
     [java] [test] SQL for updating Category: UPDATE "CATEGORY" SET
"category"=?,"comment"=? WHERE "
cat_code"=? AND "category"=? AND "comment"=?
     [java] [test] SQL for loading Category:  SELECT
"CATEGORY"."category","CATEGORY"."comment","COU
RSE_CATEGORY"."course_code" FROM "CATEGORY","COURSE_CATEGORY" WHERE
"CATEGORY"."cat_code"*="COURSE_C
ATEGORY"."cat_code" AND "CATEGORY"."cat_code"=?
     [java] [test] SQL for creating Course: INSERT INTO "COURSE"
("course_code","course_name","progr
am_code","descr","status","comment") VALUES (?,?,?,?,?,?)
     [java] [test] SQL for deleting Course: DELETE FROM "COURSE" WHERE
"course_code"=?
     [java] [test] SQL for updating Course: UPDATE "COURSE" SET
"course_name"=?,"program_code"=?,"de
scr"=?,"status"=?,"comment"=? WHERE "course_code"=? AND "course_name"=? AND
"program_code"=? AND "de
scr"=? AND "status"=? AND "comment"=?
     [java] [test] SQL for loading Course:  SELECT
"COURSE"."course_name","COURSE"."program_code","C
OURSE"."descr","COURSE"."status","COURSE"."comment","COURSE_CATEGORY"."cat_c
ode" FROM "COURSE","COUR
SE_CATEGORY" WHERE "COURSE"."course_code"*="COURSE_CATEGORY"."course_code"
AND "COURSE"."course_code
"=?
     [java] [test] SELECT
"CATEGORY"."cat_code","CATEGORY"."category","CATEGORY"."comment","COURSE_C
ATEGORY"."course_code" FROM "CATEGORY","COURSE_CATEGORY" WHERE
"CATEGORY"."cat_code"*="COURSE_CATEGO
RY"."cat_code" AND ("CATEGORY"."category" = ?)
     [java] [test] Castor: Loading Course (J2EE05)
     [java] [test] Castor: Loading Course (J2ME10)
     [java] [test] Castor: Loading Course (OOP230)
     [java] [test] Castor: Loading Course (PALM05)
     [java] [test] Castor: Loading Course (RTS200)
     [java] [test] Castor: Loading Course (TTJV00)
     [java] [test] Castor: Loading Course (TTJV03)
     [java] [test] Castor: Loading Course (TTJV05)
     [java] [test] Castor: Loading Course (TTJV10)
     [java] [test] Castor: Loading Course (TTJV12)
     [java] [test] Castor: Loading Course (TTJV15)
     [java] [test] Castor: Loading Course (TTJV25)
     [java] [test] Castor: Loading Course (TTJV28)
     [java] [test] Castor: Loading Course (TTJV29)
     [java] [test] Castor: Loading Course (TTJV30)
     [java] [test] Castor: Loading Course (TTJV35)
     [java] [test] Castor: Loading Course (TTJV38)
     [java] [test] Castor: Loading Course (TTJV39)
     [java] [test] Castor: Loading Course (TTJV42)
     [java] [test] Castor: Loading Course (TTJV45)
     [java] java.sql.SQLException: [CAIT_DB]Invalid column name 'cat_code'.
     [java]     at com.inet.tds.a.a(Unknown Source)
     [java]     at com.inet.tds.b.do(Unknown Source)
     [java]     at com.inet.tds.b.executeQuery(Unknown Source)
     [java]     at
org.exolab.castor.jdo.engine.SQLEngine$SQLQuery.execute(SQLEngine.java:1582)
     [java] [test] Castor: Loading Course (TTJV48)
     [java] [test] Castor: Loading Course (TTJV55)
     [java] [test] Castor: Loading Course (TTJV59)
     [java] [test] Castor: Loading Course (TTJV65)
     [java] [test] Castor: Loading Course (XML300)
     [java]     at
org.exolab.castor.persist.TransactionContext.query(TransactionContext.java:6
16)
     [java]     at
org.exolab.castor.jdo.engine.OQLQueryImpl.execute(OQLQueryImpl.java:457)
     [java] [test] Castor: Loading Category (42)
     [java]     at
org.exolab.castor.jdo.engine.OQLQueryImpl.execute(OQLQueryImpl.java:404)
     [java]     at Test.run(Test.java:53)
     [java]     at Test.main(Test.java:19)
     [java] [test] SELECT
"COURSE"."course_code","COURSE"."course_name","COURSE"."program_code","COU
RSE"."descr","COURSE"."status","COURSE"."comment","COURSE_CATEGORY"."cat_cod
e" FROM "COURSE","COURSE
_CATEGORY" WHERE "COURSE"."course_code"*="COURSE_CATEGORY"."course_code" AND
("COURSE"."cat_code" =
? AND "COURSE"."program_code" = ? AND "COURSE"."status" = ?)


Any help would be appreciated.

Adam

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to