I am doing something very similar to what you are trying to do... Here's how I addressed the problem: I have a series of Objects that map to the db tables (I call them data objects). I also have a series of Objects (i call them view objects, almost exact duplicates of the data Objects) that I use to send information back and forth from the data tier to the web (form) tier.
Let's say I want to edit a Person object with id 12345. I do an OJB query with id 12345... I convert this Person object into a view object so that I can display/modify in a view (a jsp page/form). when I press "submit" to save the changes, i collect the information from the jsp form into a person view and send it to the persistence layer.. the persistence layer then queries OJB for the data object with id 12345. I lock the object and copy attributes from the view object into the data object. at the end, I close the transaction. This is the best architecture I could come up with... This may not be *the absolute best* but it works for my needs. Axel Guerrero -----Original Message----- From: Philippe Boisaubert [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 26, 2003 10:30 AM To: [EMAIL PROTECTED] Subject: Changing object properties outside the transaction ... About using/design with ODMG API : Generally I want to get a domain (business) object from the persistence layer. Then I use it in my app (webapp), modify it and when modification are validated, update it in the persistent storage. I use a class for persistence actions (CRUD) like this : class BookPersistence { static BookPersistence getInstance() {...} Book getBook(String bookId) { ...} void storeBook(Book b) { ...} void deleteBook(Book b) { ...} void updateBook(Book b) { ...} } And I use it like this : Book b = new Book(); BookPersistence.getInstance().store(b); ... And : Book b1 = BookPersistence.getInstance().getBook("bookID"); b1.setXXX(...); ... BookPersistence.getInstance().updateBook(b1); Whith an update method like this : public void updateBook(Book b) { tx.begin(); tx.lock(myBook , Transaction.WRITE); tx.commit; } It doesn work 'cause book is modified outside the transaction and OJB doesn't "monitor" it (I think). Same things with : public void updateBook(Book b) { tx.begin(); OQLQuery query = odmg.newOQLQuery(); query.create("select book from "+ Book.class.getName()+ " where code=\""+ b.getCode()+ "\""); DList results = (DList) query.execute(); Book myBook = (Book) results.get(0); tx.lock(myBook , Transaction.WRITE); tx.commit; } But I can't open a transaction during all the modification time of my object and commit at the end, isn't it ? If I use this object in a webapp (modification by a form), I must wait all the validation (and request, validation, ...) before commiting. It retains lock during this time (even if I use optimistic locking, a long time transaction can desynchronize data with multiple users). And I've got to add Transaction demarcation in my business process code. So I try to declare the object dirty in my transaction like this : public void updateBook(Book b) { tx.begin(); tx.lock(b, Transaction.WRITE); ((TransactionImpl)tx).makeDirty(b); tx.commit; } It works but it's not a standardized process (the makeDirty() of TransactionImpl object is not part of ODMG API and force db calls even if the object is not modified). So what's the solution ? Am I obliged to modify the object properties inside the transaction ? Do I use bad patterns ? Is there any trick ? Thanx --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]