views:

342

answers:

0

My bidirectional collection mapping seems to only work in one direction. One job will have some number of costs. Each cost is associated with one job. The problem is, when I load a job, the costs collection is empty. However, when I load a cost and navigate from it to the job and then check the costs collection, it is properly filled. Can anyone tell me what I'm missing.

Job.hbm.xml

<hibernate-mapping>
    <class name="Job" table="jobs">
        <id column="contract" name="id" type="string">
            <generator class="assigned"/>
        </id>
        <property column="manager" name="manager" type="string"/>
        <property column="startdate" name="startDateAsInt" type="integer"/>
        <property column="orjenddate" name="originalEndDateAsInt" type="integer"/>
        <property column="status" name="status" type="JobStatus"/>
        <many-to-one class="com.fready.pjc.accpac.data.Customer" column="customer" name="customer"/>
        <many-to-one column="ctuniq" name="details" not-null="false" unique="true"/>
        <set name="costs" inverse="true">
            <key column="contract"/>
            <one-to-many class="Cost"/>
        </set>
        <set inverse="true" name="invoiceDetails">
            <key column="contract"/>
            <one-to-many class="InvoiceDetail"/>
        </set>
    </class>
    <query name="allJobs">
    from Job
    </query>
</hibernate-mapping>

Cost.hbm.xml

<hibernate-mapping>
    <class name="Cost" table="costs">
        <composite-id>
            <key-property access="field" column="contract" name="contract"/>
            <key-property access="field" column="transnum" name="transactionNumber"/>
        </composite-id>
        <property access="field" column="costrev" name="costRevenue" type="integer"/>
        <property access="field" column="doctype" name="docType" type="integer"/>
        <property access="field" column="type" name="typeCode" type="integer"/>
        <property column="transdate" name="dateAsInt" type="integer"/>
        <property column="extamthm" name="amount" type="big_decimal"/>
        <many-to-one class="com.fready.pjc.accpac.data.Job" column="contract" insert="false" name="job" update="false" not-null="true"/>
    </class>
    <query name="allCosts">
    from Cost
    </query>
    <query name="byContract">
    from Cost where contract = :contract
    </query>
</hibernate-mapping>

related questions