Alexander Snaps on 01/05/08 12:02, wrote:
On Thu, May 1, 2008 at 12:49 PM, Adam Hardy <
[EMAIL PROTECTED]> wrote:

Alexander Snaps on 01/05/08 11:30, wrote:

Using the JPA extended persistence context (not EJB), the clear() will
eliminate any changes to the model before JPA comes to flush to the
db. I
assume it would work in an EJB container too.


I'm not really sure I get the point your making here, but if you just do
not
want the EntityManager not flush to the database, shouldn't you rather
just
update the model outside of the transaction.

I mean persistent entities in the extended persistence context. Within or
outside a transaction shouldn't affect the EntityManager, which will still
flush updates to the database when closed.



Not if no tx was ever started...

Entity myEntity = em.find(Entity.class, someId);


oldValue = myEntity.getSomeField(); // this is only for further down in the
mail ;)
myEntity.setSomeField(someValue);

if(!hasError) {
  EntityTransaction tx = em.getTransaction();
  tx.begin();
  tx.commit(); // Flushes state to DB
} else {
  // do whatever _outside_ of any transaction, like re-ask user to re-enter
data
}

Sorry to doubt you, but are you 100% sure on that? I could check for myself but I don't have half an hour at the moment.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to