Hi August,

this sounds like a genuine bug to me. Can you please create a new issue
in jira and attach all information from this mail thread. Can you please
also tell us about the Castor version you use?

As I recently committed some improvements to handling of extended
entities, would there be a chance that you try this with 1.3RC1?

I'll be offline most of the time next week but will try to find some
time do some testing with regard to the problem at hand. Will keep you
informed about my findings.

Regards
Ralf


August Detlefsen schrieb:
> I should also mention that the actual Node object does get updated, just not 
> the Emissions. So as I loop through, the modifiedBy and modifiedDate fields 
> in Node are getting set and those new values are properly stored in the DB. 
>
> Regards,
> August
>
>
>
>
>
> ----- Original Message ----
> From: August Detlefsen <[EMAIL PROTECTED]>
> To: dev@castor.codehaus.org
> Sent: Friday, October 31, 2008 9:13:09 AM
> Subject: Re: [castor-dev] Persistent Objects not updating in for loop
>
> Emissions is a polymorphic object, extending from Node: 
>
>   <!-- Mapping for Emissions -->
>   <class name="org.openeco.footprint.model.Emissions" 
> extends="com.codemagi.servlets.model.Node" identity="id">
>       <description>An actual emission for one month</description>
>       <cache-type type="none"/>
>       <map-to table="emissions_data" xml="emissions-data" />
>       <field name="id" type="integer">
>           <sql dirty="ignore" name="node_id" type="integer"/>
>           <bind-xml name="id" node="element"/>
>       </field>
>       <field name="source" type="org.openeco.footprint.model.Source">
>           <sql dirty="ignore" name="source_id"/>
>           <bind-xml name="source" node="element"/>
>       </field>
>       <field name="sourceName" type="org.openeco.footprint.model.SourceName">
>           <sql dirty="ignore" name="source_name_id"/>
>           <bind-xml name="source-name" node="element"/>
>       </field>
>       <field name="orgId" type="integer">
>           <sql dirty="ignore" name="org_id" type="integer"/>
>           <bind-xml name="org-id" node="element"/>
>       </field>
>       <field name="startDate" type="date">
>           <sql dirty="ignore" name="start_date" type="date"/>
>           <bind-xml name="start-date" node="element"/>
>       </field>
>       <field name="CO2" type="float" >
>           <sql name="co2_emissions" type="numeric"/>
>           <bind-xml name="CO2" node="element"/>
>       </field>
>       <field name="CH4" type="float" >
>           <sql name="ch4_emissions" type="numeric"/>
>           <bind-xml name="CH4" node="element"/>
>       </field>
>       <field name="N2O" type="float" >
>           <sql name="n2o_emissions" type="numeric"/>
>           <bind-xml name="N2O" node="element"/>
>       </field>
>       <field name="HFC" type="float" >
>           <sql name="hfc_emissions" type="numeric"/>
>           <bind-xml name="HFC" node="element"/>
>       </field>
>       <field name="PFC" type="float" >
>           <sql name="pfc_emissions" type="numeric"/>
>           <bind-xml name="PFC" node="element"/>
>       </field>
>       <field name="SF6" type="float" >
>           <sql name="sf6_emissions" type="numeric"/>
>           <bind-xml name="SF6" node="element"/>
>       </field>
>       <field name="totalCO2" type="float" >
>           <sql name="total_co2_equivalent" type="numeric"/>
>           <bind-xml name="total-co2" node="element"/>
>       </field>
>       <field name="type" type="org.openeco.footprint.model.FuelType">
>           <sql name="fuel_type_id"/>
>           <bind-xml name="fuel-type" node="element"/>
>       </field>
>       <field name="fuelUnit" type="org.openeco.ghg.model.Units">
>           <sql name="fuel_unit_id" />
>           <bind-xml name="fuel-unit" node="element"/>
>       </field>
>       <field name="fuelAmount" type="float" >
>           <sql name="fuel_amount" type="numeric"/>
>           <bind-xml name="fuel-amount" node="element"/>
>       </field>
>       <field name="activityUnit" type="org.openeco.ghg.model.Units">
>           <sql name="activity_unit_id" />
>           <bind-xml name="activity-unit" node="element"/>
>       </field>
>       <field name="activityAmount" type="float" >
>           <sql name="activity_amount" type="numeric"/>
>           <bind-xml name="activity-amount" node="element"/>
>       </field>
>   </class>
>
>
>   <!-- Mapping for Node -->
>   <class name="com.codemagi.servlets.model.Node" identity="id" 
> key-generator="IDENTITY">
>       <cache-type type="none"/>
>       <description>Node, the base class for all object types</description>
>       <map-to table="node" xml="node" />
>       <field name="id" type="integer">
>           <sql dirty="ignore" name="node_id" type="integer"/>
>           <bind-xml name="id" node="element"/>
>       </field>
>       <field name="name" type="string" >
>           <sql dirty="ignore" name="node_name" type="varchar"/>
>           <bind-xml name="name" node="element"/>
>       </field>
>       <field name="className" type="string" >
>           <sql dirty="ignore" name="class_name" type="varchar"/>
>           <bind-xml name="class-name" node="element"/>
>       </field>
>       <field name="createdBy" type="org.openeco.login.model.User">
>           <sql dirty="ignore" name="created_by" />
>           <bind-xml name="created-by" node="element" transient="true" />
>       </field>
>       <field name="createdDate" type="date">
>           <sql dirty="ignore" name="created_date" type="timestamp"/>
>           <bind-xml name="created-date" node="element"/>
>       </field>
>       <field name="modifiedBy" type="org.openeco.login.model.User">
>           <sql dirty="ignore" name="modified_by" />
>           <bind-xml name="modified-by" node="element" transient="true"/>
>       </field>
>       <field name="modifiedDate" type="date">
>           <sql dirty="ignore" name="modified_date" type="timestamp"/>
>           <bind-xml name="modified-date" node="element"/>
>       </field>
>       <field name="ipAddress" type="string" >
>           <sql dirty="ignore" name="ip_address" type="varchar"/>
>           <bind-xml name="ip-address" node="element"/>
>       </field>
>       <field name="parent" type="com.codemagi.servlets.model.Node">
>           <sql dirty="ignore" name="parent_id" many-table="node_node_xref" 
> many-key="child_id" />
>           <bind-xml name="parent"/>
>       </field>
>       <field name="terms" type="com.codemagi.servlets.model.Term" 
> collection="arraylist">
>           <sql dirty="ignore" name="term_id" many-table="term_node_xref" 
> many-key="node_id" />
>           <bind-xml name="terms"/>
>       </field>
>       <field name="children" type="com.codemagi.servlets.model.Node" 
> collection="arraylist">
>           <sql dirty="ignore" name="child_id" many-table="node_node_xref" 
> many-key="parent_id" />
>           <bind-xml name="children"/>
>       </field>
>       <field name="users" type="org.openeco.login.model.User" 
> collection="arraylist">
>           <sql dirty="ignore" name="user_id" many-table="node_user_xref" 
> many-key="node_id" />
>           <bind-xml name="users"/>
>       </field>
>   </class>
>
>
>
>
>
> ----- Original Message ----
> From: Werner Guttmann <[EMAIL PROTECTED]>
> To: dev@castor.codehaus.org
> Sent: Friday, October 31, 2008 1:10:19 AM
> Subject: Re: [castor-dev] Persistent Objects not updating in for loop
>
> August,
>
> what does the mapping look like for Emission entities ?
>
> Werner
>
> August Detlefsen wrote:
>   
>> Greetings. I am having an issue getting persistent objects to update when 
>> they are updated inside a for() loop. Here's the scenario: 
>>
>> We are storing CO2 emissions over the course of a span of months. For each 
>> month, there is either an existing emission to be updated, or we need to 
>> create a new one. 
>>
>> Any new objects we create in the course of the loop are getting added to the 
>> database properly, but existing objects that updated are not getting 
>> persisted and the changes do not show up in the DB. 
>>
>> The code works like this: 
>>
>>             //load up all existing emissions in the span                     
>>                                                                              
>>                         
>>             HashMap existingEmissions = new HashMap();
>>             oql = db.getOQLQuery(" SELECT e FROM 
>> org.openeco.footprint.model.Emissions e " +
>>                                  " WHERE e.sourceName.id = $1 " +
>>                                  " AND e.startDate >= $2 AND e.startDate <= 
>> $3 ");
>>             oql.bind(name.getId());
>>             oql.bind(startDate);
>>             oql.bind(endDate);
>>
>>             results = oql.execute();
>>             while (results.hasMore()) {
>>                 Emissions e = (Emissions)results.next();
>>                 existingEmissions.put(e.getStartDate(), e);
>>             }
>>
>>             // Explicitly close the QueryResults                             
>>                                                                              
>>                         
>>             results.close();
>>
>>             // Explicitly close the OQLQuery                                 
>>                                                                              
>>                         
>>             oql.close();
>>
>>             //for each month in the span, create or edit emission            
>>                                                                              
>>                                    
>>             for (int i = 0; i < span; i++) {
>>
>>                 Date emissionDate = DateUtils.addMonths(startDate, i);
>>                 log.debug("Checking for emission with name: " + name.getId() 
>> + " and date: " + emissionDate);
>>
>>                 Emissions emission = 
>> (Emissions)existingEmissions.get(emissionDate);
>>                 log.debug("Existing emissions: " + emission + " persistent? 
>> " + db.isPersistent(emission));
>>                 if (emission == null) {
>>                     emission = new Emissions();
>>                     emission.setSourceName(name);
>>                     emission.setStartDate( emissionDate );
>>                 }
>>
>>                    //set new values into emission 
>>                 emission.setCO2(CO2);
>>                 emission.setCH4(CH4);
>>                 emission.setN2O(N2O);
>>                 emission.setHFC(HFC);
>>                 emission.setPFC(PFC);
>>                 emission.setSF6(SF6);
>>                 emission.setTotalCO2(totalCO2);
>>
>>                 if (emission.getId() == null) {
>>                     log.debug("Creating new emission: " + emission);
>>                     db.create(emission);
>>                 }
>>
>>             }
>>
>>             //save changes to db                                             
>>                                                                              
>>                         
>>             log.debug("About to commit...");
>>             db.commit();
>>             log.debug("Done.");
>>
>>
>> I've checked all the code and eliminated all the usual suspects: 
>>
>> - Emissions are not loaded with Database.ReadOnly
>> - Added and removed <sql dirty="ignore" from mappings
>> - No access="read-only" in mappings
>> - The database user does have UPDATE permissions on the table in question
>>
>> In addition, we have a separate method that just updates a single existing 
>> Emissions and that method does store the changes properly in the database, 
>> so we know that there is nothing preventing this object from being updated 
>> under normal circumstances. 
>>
>> So what could be causing this? Are there any known issues with JDO updates 
>> inside a for() loop? 
>>
>> Thanks,
>> August
>>
>>
>>
>>      
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>       
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>       
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>   

-- 

Syscon Ingenieurbüro für Meß- und Datentechnik GmbH
Ralf Joachim
Raiffeisenstraße 11
72127 Kusterdingen
Germany

Tel.   +49 7071 3690 52
Mobil: +49 173 9630135
Fax    +49 7071 3690 98

Internet: www.syscon.eu
E-Mail: [EMAIL PROTECTED]

Sitz der Gesellschaft: D-72127 Kusterdingen
Registereintrag: Amtsgericht Stuttgart, HRB 382295
Geschäftsleitung: Jens Joachim, Ralf Joachim

Reply via email to