users@glassfish.java.net

Re: Catching Database contraint violations within EJBs

From: <glassfish_at_javadesktop.org>
Date: Sat, 04 Apr 2009 04:48:26 PDT

Thanks for the reply,

I always want to be careful with my use of flush() for synchronizing with the database. Because I think it is an overkill to call flush() after every persist() in all my EAO beans. So, I ask

1. Do you think that setting the flushMode for the entityManager to FlushModeType.COMMIT will give the same effect and let me catch the exception. This means that at the end of every method marked with TransactionAttributeType.REQUIRED, the flush will take place and I can therefore catch the exception.
2. Though I am yet to try this out, I am thinking that a rollback on a method operation that called flush will not work because the rollback will be working after the synchronization. Example, If I have 5 objects to persist and I am doing it in a for loop. For every insert, I call the EAO bean for an insert operation which makes use of flush(), and the fourth object in the list fails because of constraint violation, though I am supposed to rollback the entire list back, I might I lost the ability to roll everything back because of flush(). How true is this?

Expecting a reply.
Regards.
[Message sent by forum member 'okmich' (okmich)]

http://forums.java.net/jive/thread.jspa?messageID=340574