users@glassfish.java.net

Re: JPA - entityManager.flush()

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Tue, 15 May 2007 23:05:30 +0200

I am not sure if I understand the problem correctly, what you state is
that such a code will throw exception?

--------TRANSACTION BEGINS----------
Collection<SomeEntity> entities = em.createNamedQuery(...).getResultList();

for (SomeEntity currEntity : entities) {
  currEntity.setSomeBooleanFlag(true);
  mergeEntity(currEntity);
}

em.flush(); // <-- this is optional

for(SomeEntity currEntity : entities) {
  if (!currEntity.getSomeBooleanFlas()) throw new RuntimeException();
}
--------TRANSACTION ENDS----------

Is that code is going to throw RuntimeException in your case?



2007/5/15, glassfish_at_javadesktop.org <glassfish_at_javadesktop.org>:
> I'm not sure I fully understand the problem...
>
> In a parallel transaction, you won't see those changes because of the read-committed isolation level in the database.
>
> In the same transaction (and more specific in the same EM), you should see all the changes made to the entities in this persistence context because this is how persistence context should behave.
>
> So your only option to check the flush is to execute a native query (or a JDBC query that uses the same transactional connection).
>
> Regards,
> -marina
> [Message sent by forum member 'mvatkina' (mvatkina)]
>
> http://forums.java.net/jive/thread.jspa?messageID=217140
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>