-
1. Re: Conversation and Manual Flush Mode
pmuir Nov 12, 2007 12:58 PM (in response to dapeng)Don't confuse transaction commits with flushing the persistence context flushes. Manual flush mode doesn't alter the transaction commits at all.
I don't really understand what you are after? You want to interpose a control layer that just exposes the EntityManager methods but with a non standard API? Doesn't sound sensible to me. -
2. Re: Conversation and Manual Flush Mode
dapeng Nov 13, 2007 4:01 AM (in response to dapeng)Hi, Pete,
I know the difference bet. tx-commit and persistence context flush. My question is, whether the manual flush is always the best strategy for a conversation, when I don't want to see modified data in the database permaturely, before the conversation is completed.
in Seam examples and documentation the manual flush is called in the JSF layer. But in my layered application, I would not like to expose the entitymanager to the JSF layer but to keep in the "backend layers" (service + dao).
Do you have a suggestion, how to handle the manual flsuh without exposing the entity manager in the jsf layer? -
3. Re: Conversation and Manual Flush Mode
pmuir Nov 13, 2007 6:23 AM (in response to dapeng)"dapeng" wrote:
I know the difference bet. tx-commit and persistence context flush.
Good :) - a common mistake!My question is, whether the manual flush is always the best strategy for a conversation, when I don't want to see modified data in the database permaturely, before the conversation is completed.
IMO, yes.in Seam examples and documentation the manual flush is called in the JSF layer. But in my layered application, I would not like to expose the entitymanager to the JSF layer but to keep in the "backend layers" (service + dao).
You can control the flushmode both through annotations/xml and programatically through PersistenceProvider.instance().setManualFlushMode(em); You have to use a Seam Managed Persistence Context though. I would probably make the service layer set the flush mode, but then this is definitely not how I would design an application. -
4. Re: Conversation and Manual Flush Mode
dapeng Nov 13, 2007 12:31 PM (in response to dapeng)How will you then design your application? Get rid of the layered architecture?
You can control the flushmode both through annotations/xml and programatically through PersistenceProvider.instance().setManualFlushMode(em); You have to use a Seam Managed Persistence Context though. I would probably make the service layer set the flush mode, but then this is definitely not how I would design an application.
I chose a solution where I use an aspect to flush the persistence context after invocation of all methods with @End annotation. Any comment? I tried to do the same to switch the flush mode to manual on all methods with @Begin annotation. But this didn't work as expected. It seems that the javaassist code instrumentation overwrites or got messed up with the aspectj instrumentation. Maybe I'd better choose Seam interceptor instead of Aspectj. Only in that case I have to either reference the interceptor or an annotation based on the interceptor in all action classes. Do you have a better idea, how to solve this problem? Can I put the annotation once in an abstract super class?
Thx. -
5. Re: Conversation and Manual Flush Mode
pmuir Nov 16, 2007 6:25 AM (in response to dapeng)Take a look at the wiki example, this uses some simple layering.
Interceptors have to be placed on each Seam component (we have an open jira to allow custom interceptors to be applied across selected components). -
6. Re: Conversation and Manual Flush Mode
joaobmonteiro Nov 17, 2007 7:16 PM (in response to dapeng)"dapeng" wrote:
Hi,
I hope that I understand everything in the right way. Seam always starts and commits 2 Tx for each request. By default flush type of AUTO, hibernate entity manager will also commit the 2 txs. (
Hi, I really need to understand when Seam starts a new transaction. I saw that you realize how it happens. Could you tell me you source of this information or explain it better?
I have a similar situation (service + dao) and some problems with transactions because flush() is called after any dao operation, and many times I do not desire that.
Thanks! -
7. Re: Conversation and Manual Flush Mode
dapeng Nov 23, 2007 8:19 AM (in response to dapeng)If you have transaction enabled in seam, it will start 1 tx for phase 1 to 5 of JSF lifecycle. Then commits the 1 tx, which should lead to a flush. Then Seam will start a 2 tx for phase 6 of JSF lifecycle and immediately commits that after that.