From: Adrian Robert <[EMAIL PROTECTED]>
Date: May 10, 2004 2:52:35 PM EDT
To: [EMAIL PROTECTED]
Subject: Unable to load two levels of 1:n relationship

Hi,

I cannot seem to load a set of objects each having a 1:n relation to
a second set of objects which each have a 1:n relation to a third set.
I CAN load objects with just one level of 1:n relation without error.

Department   has collection of:
    Employee   has collection of:
        Review

    <class name="Department" identity="id"
           key-generator="MAX" access="db-locked">
        <map-to table="departments" />
        <field name="id" type="integer">
            <sql name="id" type="integer" /></field>
        <!-- ... -->
        <field name="employees" collection="collection"
               type="Employee" lazy="false">
            <sql many-key="department_fk" /></field>
    </class>
    <class name="Employee" identity="id" depends="Department"
           key-generator="MAX" access="db-locked">
        <map-to table="employees" />
        <field name="id" type="integer">
            <sql name="id" type="integer" /></field>
        <!-- ... -->
        <field name="reviews" collection="collection"
               type="Review" lazy="false">
            <sql many-key="employee_fk" /></field>
    </class>
    <class name="Review" identity="id" depends="Employee"
           key-generator="MAX" access="db-locked">
        <map-to table="reviews" />
        <field name="id" type="integer">
            <sql name="id" type="integer" /></field>
        <!-- ... -->
    </class>

I am not using lazy loading (due to need for long transactions).  I
tried with access="shared" and access="db-locked".  I tried with and
without putting relations in the reverse direction in the mapping
file.  I am loading with an OQL query:

        db.begin();
        Query query = db.getOQLQuery("SELECT d FROM Department d;");
        QueryResults results = query.execute(Database.ReadOnly);
        List list = Collections.list(results);
        results.close();
        query.close();
        db.commit();
        db.close();

With "shared" access, I get:

java.lang.IllegalStateException: Transaction [EMAIL PROTECTED] does not hold the read lock: org.brainml.modelserver.domain.Model/1/0 -/-!
java.lang.IllegalStateException: Transaction [EMAIL PROTECTED] does not hold the read lock: org.brainml.modelserver.domain.Model/1/0 -/-!
at org.exolab.castor.persist.LockEngine$TypeInfo.assure(LockEngine.java: 1279)



With "db-locked" access (and using 'query.execute(Database.DbLocked)'), I get:

2004-05-10 14:54:22 BMLMS: Error : Exception: Nested error: java.sql.SQLException: ERROR: SELECT FOR UPDATE cannot be applied to a join
while executing SELECT "models"."id","models"."created","models"."last_modified","models"."late st_version","models"."name","models"."keywords","models"."description"," models"."submitter_fk","versions"."id" FROM "models" LEFT OUTER JOIN "versions" ON "models"."id"="versions"."model_fk" FOR UPDATE
java.sql.SQLException: ERROR: SELECT FOR UPDATE cannot be applied to a join


at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:126)


I am using PostgreSQL 7.3. Since this seems like a fairly simple case I'm surprised I'm having trouble. Is there something obvious I'm missing?

thanks..



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

Reply via email to