-
1. Re: Trying to understand Seam Managed Transactions
gjeudy Aug 27, 2008 3:15 PM (in response to cbrautigam)I would recommend using Seam managed transactions. There is obviously something wrong in your case. Can you provide a detailed usecase with code samples and log entries ?
It could just be some peculiar setup in your hibernate/JPA mappings ? (I'm thinking cascading relationships here)
-
2. Re: Trying to understand Seam Managed Transactions
javacoryd Aug 27, 2008 5:10 PM (in response to cbrautigam)This is classic behavior that we and many others have seen, but makes sense after you know what is happening.
Seam, of course, allows you to throw the entity beans right up onto the JSF pages ( as backing beans ). During the JSF lifecycle, the request values from the JSF page are applied to the backing beans which are the entities. The entities are registered in the entity manager so they are flushed without you needing to call persist.
There are a couple of ways to get around this, but the way we have managed this is to:
1) Use a seam managed persistence context registered in components.xml.
2) Begin a conversation when the page is loaded.
3) Set the flush mode toMANUAL
when the conversion is begun ( either in pages.xml or through annotations ).This way, when you truly want to save your changes you simply call entityManager.flush().
Cory.
-
3. Re: Trying to understand Seam Managed Transactions
gjeudy Aug 27, 2008 7:03 PM (in response to cbrautigam)Cory, well understood but I don't think it answers Craig's problem.
In Seam managed transaction model, there are 2 transactions in a single JSF request cycle. One enclosing UPDATE MODEL VALUE to INVOKE APPLICATION phases inclusively and the 2nd enclosing RENDER RESPONSE phase.
If I understand correctly Craig is mentioning that the DB update is happening before the INVOKE APPLICATION phase. This doesn't make sense to me because in a regular AUTO flush mode the entityManager should only flush at the end of the transaction which means in our case at the end of the INVOKE APPLICATION phase. There are other conditions when an early DB flush could happen. (for example when querying for a newly persisted entity e.g. not yet flushed would trigger an INSERT in order for the query to succeed) but without more details from the usecase I cannot tell if these apply here.
-
4. Re: Trying to understand Seam Managed Transactions
javacoryd Aug 27, 2008 9:30 PM (in response to cbrautigam)Ah yes, thanks for clearing that up Guillaume.
As you have mentioned, a possible
flush before find
is being executed for some reason before the application phase ( and after the model has been updated of course ).Regardless, if you execute
validation
in the application phase and don't want the changes persisted ifvalidation
fails, you will need to either setup the manual flush mode or evict the entities from the entity manager ( this is not suggested as the lazy relationships will die ).Craig, could you post the command button .xhtml and the action?
Thanks,
Cory.
-
5. Re: Trying to understand Seam Managed Transactions
cbrautigam Aug 29, 2008 6:44 AM (in response to cbrautigam)I'll get that posted here after holiday. Thanks for the help.