Hi,

My object model is: Company has BusinessUnits. A BusinessUnit has Probes.
I need to add a Probe to a BusinessUnit. A Probe must have a reference to a 
MonitoringTool.

         COMPANY
            |
            |
         depends
            |
            |
         BUSINESSUNIT
            |
            |
         depends
            |
            |
         PROBE   ----- references -----> MONITORINGTOOL



Here is the excerpt from the mapping file.


<class name="com.company.product.Company" identity="companyID"
            key-generator="SEQUENCE">
         <cache-type type="count-limited" capacity="200"/>

         <description>Company</description>
         <map-to table="Companies"/>

         <field name="companyID" type="integer">
             <sql name="companyID" type="numeric"/>
         </field>

         <field name="companyCode" type="string">
             <sql name="code" type="varchar"/>
         </field>

         [...]

         <field name="businessUnits" 
type="com.company.product.BusinessUnit" collection="arraylist">
         </field>
     </class>



     <class name="com.company.product.BusinessUnit" identity="businessUnitID"
            depends="com.company.product.Company" key-generator="SEQUENCE">
         <cache-type type="count-limited" capacity="200"/>

         <description>Business Unit</description>
         <map-to table="BusinessUnits"/>

         <field name="businessUnitID" type="integer">
             <sql name="businessUnitID" type="numeric"/>
         </field>

         <field name="company" type="com.company.product.Company" 
required="true">
             <sql name="companyID"/>
         </field>

         <field name="code" type="string">
             <sql name="code" type="varchar"/>
         </field>

        [...]

         <field name="probes" type="com.company.product.Probe" 
collection="arraylist">
         </field>
     </class>


     <class name="com.company.product.Probe" identity="probeID"
            depends="com.company.product.BusinessUnit" 
key-generator="SEQUENCE">
         <cache-type type="count-limited" capacity="200"/>

         <description>Probe</description>
         <map-to table="Probes"/>

         <field name="probeID" type="integer">
             <sql name="probeID" type="numeric"/>
         </field>

         <field name="businessUnit" type="com.company.product.BusinessUnit" 
required="true">
             <sql name="businessunitID"/>
         </field>

         [...]

         <field name="monitoringTool" 
type="com.company.product.MonitoringTool" check="ignore">
             <sql name="monitoringToolID"/>
         </field>
     </class>


     <class name="com.company.product.MonitoringTool" 
identity="monitoringToolID"
            key-generator="SEQUENCE">
         <cache-type type="count-limited" capacity="5"/>

         <description>Monitoring Tools</description>
         <map-to table="MonitoringTools"/>

         <field name="monitoringToolID" type="integer">
             <sql name="monitoringToolID" type="numeric"/>
         </field>

          <field name="description" type="string">
             <sql name="description" type="varchar"/>
         </field>
     </class>



The following method is a SessionBean method (JBoss 2.4.3)

  public Probe addProbe(BusinessUnit bu, Probe p) throws ...
     {
         try {

             Company c = (Company) 
pm.findByPrimaryKey(com.company.product.Company.class, new 
Integer(bu.getCompany().getCompanyID()));
             BusinessUnit bunit = c.getBusinessUnit(bu.getCode());

             Probe probe = new Probe(p);  // create server-side probe

             MonitoringTool mt = (MonitoringTool) 
pm.findByPrimaryKey(com.company.product.MonitoringTool.class,
                                                                      new 
Integer(p.getMonitoringTool().getMonitoringToolID()));
             System.out.println("MT found " + mt.getMonitoringToolID());
             probe.setMonitoringTool(mt);
             System.out.println("Assigned MT ID " + 
probe.getMonitoringTool().getMonitoringToolID());

              bunit.addProbe(probe);
             System.out.println("Probe added : " + probe);
             System.out.println("Whole BU " + bunit);
             return probe;

            }
           catch(...)
         }

It seems that until the method returns (transactions are bean-managed, with 
tx ="Required"), everything is good :

[Default] MT found 201
[Default] Assigned MT ID 201
[Default] Probe added : Probe 0 FDLT-PRB1 bU: FDLT-BUS1 MonitoringTool201
[Default] Whole BU BU 286 has probes: 1
                 Probe 0: Probe 0 FDLT-PRB1 bU: FDLT-BUS1 MonitoringTool 
201 belongs to: FDLT

What's more the object returned to the client contains the pointer to the 
right MonitoringTool.
For some reason, the pointer to MonitoringTool does not get persisted.

What am I missing?
Any help is appreciated!


-- Jacek



Jacek Kruszelnicki
Numatica Corporation
E-mail: [EMAIL PROTECTED]
Phone: (781) 756 8064

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

Reply via email to