-
1. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
coresystems_rit Apr 21, 2009 11:41 AM (in response to coresystems_rit)I forgot to attach the two scenarios.
Doesn't work:
@Begin(flushMode = FlushModeType.MANUAL) public void beginEditEmployee(Employee employee) { try { this.employee = em.find(Employee.class, employee.getId()); } catch (Exception ex) { // ... } }
Does work:
@Begin(flushMode = FlushModeType.MANUAL) public void beginEditEmployee(Employee employee) { Session session = (Session) em.getDelegate(); session.setFlushMode(FlushMode.MANUAL); try { this.employee = em.find(Employee.class, employee.getId()); } catch (Exception ex) { // ... } }
-
2. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
coresystems_rit Apr 21, 2009 11:43 AM (in response to coresystems_rit)Damn, is there somewhere an edit link for an entry? :-)
-> The second scenario has only a @Begin() NOT @Begin(flushMode = ...).
Sorry!
-
3. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
gonorrhea Apr 21, 2009 11:20 PM (in response to coresystems_rit)is the 1st level cache (SMPC) dirty? i.e. what data is being synchronized to the db when the tx commits and the PC is flushed?
you're only showing em.find()....
here is an example from the wiki example:
CommentHome.java:
@Begin(flushMode = FlushModeType.MANUAL, join = true) public String newComment() { setEdit(true); showForm = true; return "redirectToDocument"; }
-
4. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
coresystems_rit Apr 22, 2009 7:14 AM (in response to coresystems_rit)Hi Arbi
Thanks for your answer!
The commit method (the one which executes the flush or persiste method) looks as follow:
@End(beforeRedirect = true) public void commit() { try { if (isEmployeeManagerInNewMode()) { em.persist(employee); } else { em.flush(); } } catch (Exception ex) { log.error("EmployeeManager.commit() : Could not insert or update employee. ( Exception: " + ex + ")"); } }
If I use the flushMode within the
Begin
-Annotation, as soon as any field of the employee gets updated the data gets automatically synchronized to the database.Yes the cache must be dirty because I edit the fields directly on the entity.
-
5. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
coresystems_rit Apr 22, 2009 7:50 AM (in response to coresystems_rit)Is it a problem that I inject the entity manager with @PersistenceContext?
@PersistenceContext private EntityManager em;
-
6. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
gonorrhea Apr 22, 2009 6:52 PM (in response to coresystems_rit)
flushMode FlushModeType Changes the flush mode of the Seam-managed persistence contexts
in this conversation when the conversation begins. Default:
AUTO.You most likely have to use @In instead of @PersistenceContext. It's very important to understand the difference b/n the two. Read the ref docs or Seam in Action or Yuan book for details...
-
7. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
gonorrhea Apr 22, 2009 6:54 PM (in response to coresystems_rit)actually, generally speaking with Seam apps, use @In exclusively.
IIRC, with @PersistenceContext, the PC is restricted to the life of an EJB transaction only (typically one business method), and is thus not suitable for conversations (unless you use extended=true and even then the SMPC offers other advantages).
-
8. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
coresystems_rit Apr 23, 2009 2:03 PM (in response to coresystems_rit)Yep I know the difference with @In and @PersistenceContext for Seam applications. Infact I do have a @PersistenceContext(type=EXTENDED), just forgot to write it in the post (the extended). Anyway the extended persistence context would works in my conversation, as I don't span any conversation over mutliple ejbs.
I changed now the @PersistenceContext(type=EXTENDED) to @In, so the PersistenceContext gets injected by Seam. Now it doesn't update the user if I pass the @Begin(type=MANUAL) at the beginning of the conversation.
Is there a reason why Seam can't set the FlushMode correctly on the PersistenceContext? (I use Hibernate as backing entity manager))
Thanks for your help,
Thierry
-
9. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
gonorrhea Apr 23, 2009 5:45 PM (in response to coresystems_rit)Not sure exactly why but it may be covered somewhere in Seam in Action:
If you want to use application transactions in your application (and don’t want to use
the workaround of avoiding transactional methods), you must be using a Seam-managed
persistence context and the native Hibernate API or Hibernate as the JPA provider.
MANUAL flush mode isn’t supported by any other JPA 1.0 provider.
For more in-depth coverage of application transactions, consult
chapter 11 of Java Persistence with Hibernate (Manning, 2007).Perhaps DAllen can shed some light on your question...
-
10. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
gonorrhea Apr 23, 2009 6:00 PM (in response to coresystems_rit)Here is your (partial) answer from section 9.1.2 (pay special attention to the last point!):
When an SFSB becomes a Seam component, Seam doesn’t control how a containermanaged
persistence manager is bound to the SFSB. Thus, Seam can only tune the
lifetime of the extended persistence context by managing the lifetime of the SFSB.
(Keep in mind that this has no effect on a transaction-scope persistence context on
the SFSB.) However, there are several problems with this solution:
■ It can only be used in an EJB environment (EJB session bean and JPA).
■ There are complex propagation rules2 for sharing the extended persistence
context across loosely coupled Java EE components.
■ The extended persistence context on an SFSB cannot be accessed easily from
JavaBean components.
■ Seam can’t control the flush mode of the persistence context on an SFSB (no
manual flushing).So I guess I'm still not sure what the technical answer to your question is... sorry, but I'm sure DAllen or the other Seam devs would know...
-
11. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
gonorrhea Apr 23, 2009 6:04 PM (in response to coresystems_rit)Actually I think it's b/c MANUAL flushing is not allowed/defined in JSR220 (and @PersistenceContext is part of Java EE 5 API, not Seam API, like @In), so it's actually a Hibernate extension to use MANUAL flushmode w/ @Begin.
Here: http://java.sun.com/javaee/5/docs/api/javax/persistence/PersistenceContext.html
flushMode attribute is not defined as it is with Seam's @Begin...
-
12. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
coresystems_rit Apr 23, 2009 6:13 PM (in response to coresystems_rit)True that but the Java EE 5 Entity Manager has a flush mode property: http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManager.html#setFlushMode(javax.persistence.FlushModeType). But it also has only AUTO and COMMIT as modes and not MANUAL as hibernate do. That could be the reason.
Thanks a lot for all your answer!
Thierry
-
13. Re: Set flushMode over @Begin(flushMode=MANUAL) doesn't work but session.setFlushMode(MANUAL) does
gonorrhea Apr 23, 2009 6:24 PM (in response to coresystems_rit)bottom line: use @In for EntityManager injections in Seam.
also consider this from ref doc:
Seam-managed persistence contexts are extremely efficient in a clustered environment. Seam
is able to perform an optimization that EJB 3.0 specification does not allow containers to use
for container-managed extended persistence contexts. Seam supports transparent failover of
extended persisence contexts, without the need to replicate any persistence context state between
nodes. (We hope to fix this oversight in the next revision of the EJB spec.)