Hi all,

I am new to Castor JDO (though have been loving Castor
XML for a while now), and I am having a bit of
confusion. Some background:

My app is going to consist of client software whose
persistence layer is XML. So, when a user saves an
object, it is marshalled to an XML file. At some point,
the client app is pointed at a server app that will
save the objects stored in the client's XML files to a
central database. If the object has not yet been
entered, I need a new entry to be made (like SQL
insert), and if the object has already been saved (ie
if its primary key exists in the table), I need the
database to be updated with changes from the client
(like an SQL update).

The first scenario works fine, but I can't quite figure
out how to handle updating existing records. What I'd
like is to be able to do something like this:

MyObject o = getObjectFromClient();
//determine that o's primary key already exists in the
table
db.begin();
db.update(o);
db.commit();

However, that throws
org.exolab.castor.jdo.DuplicateIdentityException, which
makes me think update() doesn't really work that way at
all. In fact, given the examples (not really many
update() examples with the source that I found), the
only way I can see to accomplish what I need is
something like:

MyObject o = getObjectFromClient();
//determine that o's primary key already exists in the
table
db.begin();
//create a OQL query to get the existing record
results = query.execute();
MyObject objInDb = (MyObject)results.next();
objInDb.setProperty1(o.getProperty1);
objInDb.setProperty2(o.getProperty2);
//etc....
db.commit();

That's the best idea I have had. Can this technique
really be the way to go? It'll sure be hard to maintain
if properties in my object change, and more bug-prone
too.

So, I guess what I need to know before taking this
approach is, is there a way to update a JDO object
without first acquiring that JDO object from the
database? Or do I have to first get the object from the
db and then manually set the values of the changed
properties?

Thanks in advance for any help. Also, thanks for your
patience with my pseudo-code and ramblings. It's about
6 million degrees in my office at the moment and the
brain is starting to melt.

Gregg

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

Reply via email to