Hi,

I just started my second cayenne related project and found that I am doing the same "workaround" that I did on the first one. Now I wonder if there is
a better way to do it:

My apps usually have a shopping basket BASKET with a simple relation to i.e. BOOKS (via BASKET.isbn -> BOOKS.isbn). Now, I want customers to be able to add
to the basket without being logged in and so my basket rows might not be
committed to the database unless the user logs in. At that point my session which holds all uncommitted basket rows will load in existing basket rows from
the db and commit.

All this only works if I add the following overwrite to my super Basket class. Not a very nice way but proven and stable. Is there a less manual way to do this?

/Andreas Pardeike



public class Basket extends _Basket
{
// we need to fetch the Book relation manually otherwise transient baskets
  // will fail to resolve getBook()

  @Override
  public void setISBN(String isbn)
  {
    super.setISBN(isbn);

Books book = DataObjectUtils.objectForPK(getObjectContext(), Books.class, isbn);
    if(book != null)
      setBook(book);
  }
}



and here's how I add a basket row:

Basket row = _context.newObject(Basket.class);
row.setISBN(newISBN);
row.setLogin(_login == null ? "" : _login);
...
if(_login != null)
  _context.commitChanges();


Reply via email to