users@glassfish.java.net

Re: JPA - entityManager.flush()

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Sun, 13 May 2007 22:46:07 +0200

em.flush() flushes data into database, but it is still active
transaction, so if you flush, but transaction is still active, you
will not see changes from within another transaction, because
databases follow ACID rule.


2007/5/13, glassfish_at_javadesktop.org <glassfish_at_javadesktop.org>:
> Hey,
> I was wondering regarding the behaviour of em.flush();
>
> I have such a method:
> public void testMethod() {
>
> Collection<SomeEntity> entities = em.createNamedQuery(...).getResultList();
>
> for (SomeEntity currEntity : entities) {
> currEntity.setSomeBooleanFlag(true);
> mergeEntity(currEntity);
> }
>
> em.flush();
>
>
> for(SomeEntity currEntity : entities) {
> //Perform some stuff here...
> }
> }
>
> public void mergeEntity(SomeEntity entity) {
> em.merge(entity);
> }
>
> I expected that after calling em.flush() I will see the boolean flag set for all requests iterated in the first for loop, but it doesnt.
>
> Only after the whole method ends, I see the changes flushed in the DB,
>
> Why? shouldn't em.flush() update the database just after it got invoked?
>
>
> Thanks in advanced,
>
> Asaf.
> [Message sent by forum member 'trouby' (trouby)]
>
> http://forums.java.net/jive/thread.jspa?messageID=216665
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>