FAQ
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
Struts

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)
.
.
p.setToArtist(a);
try
{
context.commit();
}
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,
DB

Search Discussions

  • Fredrik Liden at Jul 15, 2008 at 9:49 pm
    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.

    Fredrik

    -----Original Message-----
    From: Devyandu
    Sent: Tuesday, July 15, 2008 1:49 PM
    To: user@cayenne.apache.org
    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
    Struts

    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)
    .
    .
    p.setToArtist(a);
    try
    {
    context.commit();
    }
    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,
    DB

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedJul 15, '08 at 8:32p
activeJul 15, '08 at 9:49p
posts2
users2
websitecayenne.apache.org

2 users in discussion

Devyandu: 1 post Fredrik Liden: 1 post

People

Translate

site design / logo © 2021 Grokbase