Hi again,
Thanks Bruce for the quick reply. Below is the code and mapping.
I'd also like to point out that the updates going wrong (i.e. creating new
records) used to occur out of nowhere and at a very low frequency.
I initially thought that these were some X-Files stuff :) and didn't worry
about it 'cos most of the times, the updates are OK through the same
methods.
Recently there was one whole bunch of updates that went wrong so I've
decided to bring it up to this mailing list.
Many Thanks,
Al.
P.S.: Don't pay attention to the package names, they are fake.
*************
* CLIENT CODE *
*************
// This is the part of the JAVA class where the update call is sent to
Castor JDO.
import org.exolab.castor.jdo.*;
...
public class DatabaseHandler
{
...
/**
*
* @param dbName The name of the db table.
* @param dataObj The UserDoc object. DataObject is the superclass
containing the uId attribute.
*/
public static void update(String dbName, DataObject dataObj)
throws Exception
{
JDO jdo = (JDO)_dbMap.get(dbName);
if (jdo != null)
{
Database db = getConnection(dbName);
try
{
System.out.println("Updating obj: "+ dataObj.getClass().getName() +
", UID: "+dataObj.getUId());
db.begin();
db.update(dataObj);
db.commit();
System.out.println("Updated obj: "+ dataObj.getClass().getName() +
", UID: "+dataObj.getUId());
}
catch (PersistenceException ex)
{
Exception ex2 = (Exception)ex.getException();
if (ex2 != null)
throw new Exception(ex2.getLocalizedMessage());
throw new Exception(ex.getLocalizedMessage());
}
catch (Exception ex)
{
ex.printStackTrace();
throw new Exception(ex.getLocalizedMessage());
}
finally
{
freeConnection(dbName, db);
}
}
else
//database not found in registry
throw new Exception("Database '" + dbName +"' is not loaded");
}
...
}
**********
* OUTPUT *
**********
Updating obj: com.zaboo.client.jdo.UserDoc, UID: 21708
Updated obj: com.zaboo.client.jdo.UserDoc, UID: 23304
**********
* MAPPING *
**********
<class access="db-locked" identity="uId" key-generator="KEYGEN"
name="com.zaboo.client.jdo.UserDoc">
<description>User documents</description>
<map-to table="userdoc" xml="UserDocument"/>
<field transient="false" required="true" direct="false" name="uId">
<sql dirty="check" type="integer" name="UID"/>
<bind-xml node="attribute" name="UID" match="UID"/>
</field>
<field transient="false" type="integer" required="true" direct="false"
name="senderId">
<sql dirty="ignore" name="SenderId"/>
<bind-xml node="element" name="SenderId" match="SenderId"/>
</field>
<field transient="false" type="integer" required="true" direct="false"
name="recipientId">
<sql dirty="ignore" name="RecipientId"/>
<bind-xml node="element" name="RecipientId" match="RecipientId"/>
</field>
<field transient="false" type="string" required="false" direct="false"
name="uploadDt">
<sql dirty="ignore" name="UploadDt"/>
<bind-xml node="element" name="UploadDt" match="UploadDt"/>
</field>
<field transient="false" type="string" required="false" direct="false"
name="comDt">
<sql dirty="ignore" name="ComDt"/>
<bind-xml node="element" name="ComDt" match="ComDt"/>
</field>
<field transient="false" type="string" required="true" direct="false"
name="fileName">
<sql dirty="ignore" name="FileName"/>
<bind-xml node="element" name="FileName" match="FileName"/>
</field>
<field transient="false" type="integer" required="false" direct="false"
name="status">
<sql dirty="ignore" name="Status"/>
<bind-xml node="element" name="Status" match="Status"/>
</field>
</class>
*********
* DETAILS *
*********
// -- Objects classes --
public class UserDoc
extends DataObject
{
private int _senderId;
private int _recipientId;
private String _uploadDt;
private String _comDt;
private String _fileName;
private int _status;
public UserDoc()
{
}
// ***************** Getters and setters *****************
...
}
public class DataObject implements Serializable
{
protected long _uId;
public DataObject()
{
}
// Setter and getter methods.
...
###### END ######
> -----Original Message-----
> From: Bruce Snyder [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, March 25, 2003 11:08 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] 0.8.11 - JDO Database update creates a new
> record
>
>
>
> First off, you're using a version of Castor from November 2000.
> This makes troubleshooting very difficult because a LOT of things
> have changed in Castor since then.
>
> Second, please post the client code and the mapping of the object
> in question.
>
> Bruce
> --
>
> perl -e 'print
> unpack("u30","<0G)[EMAIL PROTECTED]&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev