cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fredrik Liden <>
Subject RE: What to do with new objects if validation fails on Commit
Date Tue, 15 Jul 2008 21:48:20 GMT
Hi, every time you do context.commit(); you should probably have context.rollbackChanges();
in the catch statement to set it back to the original state and avoid the same validation
error on every consecutive commit. And possibly forward the validation error to the user in
some form.


-----Original Message-----
From: Devyandu []
Sent: Tuesday, July 15, 2008 1:49 PM
Subject: What to do with new objects if validation fails on Commit

I am new to Cayenne but enjoying using it, I have a question about what to
do with new or modified objects when a validation failure or runtime
exception happens on Commit.

This is my Environment
TomCat 5.0
Java 1.4.2
Cayenne 2.0.4

For example in my save new painting Actionclass

DataContext context=context.getgetThreadDataContext();
//Get artist object
Artist a= (Artist)DataObjectUtils.objectForPK(context,State.class, 1);
Painting p = (Painting)context.newObject(Painting.class);
//Fill in painting from Form post (I use Dozer)
catch (Exception e)
  //What to do here ???

What do I do when there is an exception, (unregisterobjects?) I do not want
the modified Artist and the new Painting sitting on the context.  Because
Cayenne would try to commit them if the user went to the gallery screen now
and changed a Gallery.

Should I not use the threadDataContext in a web app and create a new data
context for each save page to avoid this problem.

What is the convention for a web/struts app. I am sure many people have
encountered and solved this before me.
Thanks in advance,

View raw message