i do not see need for specific flush intervention as
during an active transaction your configured persistence provider handles when to flush
http://java.sun.com/javaee/5/docs/api/javax/persistence/FlushModeType.html
example of this would be I have a customer ordering books (once a month)
if I order a specific book-title (lineitem) to order for this customer and do not have customers order header (Billing ship-to) I would not want to commit the order-line-item
If I created the line-item without the required order header the DB would detect constraint violation and the DB would then rollback the line-item to its previously pre-insert condition
Does this help?
Martin
______________________________________________
Verzicht und Vertraulichkeitanmerkung / Disclaimer and confidentiality note
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
This message is confidential and may be privileged. If you are not the intended recipient, we kindly ask you to please inform the sender. Any unauthorised dissemination or copying hereof is prohibited. This message serves for information purposes only and shall not have any legally binding effect. Given that e-mails can easily be subject to manipulation, we can not accept any liability for the content provided.
> Date: Sat, 4 Apr 2009 04:48:26 -0700
> From: glassfish_at_javadesktop.org
> To: users_at_glassfish.dev.java.net
> Subject: Re: Catching Database contraint violations within EJBs
>
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
_________________________________________________________________
Rediscover HotmailŪ: Get e-mail storage that grows with you.
http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Storage1_042009