Jon Wilmoth wrote:
I have a JDO object that persists a number of fields. Two specific fields are timestamp data type fields
"startDate" & "endDate". In addition to the persisted
fields I have a java bean style method for retreiving
a calculated value (public Double
getCalculatedDurationHours() ...). This method
calculates the difference between the start and end
persistent fields. I'd like to marshall this object
(using castor xml) to include the persistent fields
plus this calculated field. I tried turning on
"auto-extends" in the mapping document for this class,
but got errors as Castor tried unsuccessfully
marshalling constants (that I wouldn't want marshalled
anyway). I then tried adding an explicite mapping for
this "field", and added a dummy setter (public
setCalculatedDurationHours(Double value){}) to avoid
an error message saying there wasn't a setter for the
mapped field.
<field name="calculatedDurationInHours" type="double" required="false"> <bind-xml name="calculatedDurationInHours" node="element" transient="false"/> </field>
Unfortunately this leads to the following error when the object is loaded:
org.exolab.castor.jdo.DataObjectAccessException: Type conversion error: could not set value of FieldMolder of com.apex.chronos.app.time.TimeEntry.setcalculatedDurationHours(double calculatedDurationHours) with value of type java.lang.Long
What's the recommended approach for marshalling non-persistent fields? If the explicite mapping is the correct approach, why is the JDO side of things failing when there is no <sql> mapping?
Jon,
It sounds like what you need is a custom FieldHandler. Take a look at this quick guide to writing a FieldHandler here:
http://brainopolis.dnsalias.com/castorwiki/Wiki.jsp?page=NonMappedNode
Bruce
--
perl -e 'print unpack("u30","<0G)[EMAIL PROTECTED]&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'
The Castor Project http://www.castor.org/
Apache Geronimo http://geronimo.apache.org/
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
