-
1. Re: What is the difference between EJB and POJO transactions
christian.bauer Apr 21, 2007 2:15 AM (in response to grettke_spdr)I haven't read the book, but the three basic transaction models are
- EJB/CMT: You have EJB components (session beans, MDBs) and you call these EJB components from whatever other code. By default, a system transaction will begin when an EJB method is called and it will be committed when that method returns. The transaction propagates into other calls, e.g. if your EJB calls another EJB. You can use annotations or XML metadata to change this default transaction assembly. Seam can emulate this behavior with the Seam-specific and proprietary @Transactional annotation on POJOs, then Seam acts as the container that manages transaction boundaries.
- JTA: You can call the JTA UserTransaction API in your application code somewhere and control the begin and end of a transaction programmatically.
- Seam-managed JTA: Seam will call the JTA API for you automatically during the JSF lifecycle, meaning it will wrap two transactions around a JSF request. One transaction starts when the request hits the server and is committed when INVOKE APPLICATION is complete. The second transaction spans only the RENDER RESPONSE phase. This is an optimized and recommended pattern in a Seam/JSF application. All EJBs and indeed any POJOs you call during that request are participating in that transaction. To enable it, configure JSF with the TransactionalSeamPhaseListener.
I recommend the last option, since it works with whatever components you execute and it is good from a scalability perspective. Also, you don't need to write any code or use any annotations with it. -
2. Re: What is the difference between EJB and POJO transactions
christian.bauer Apr 21, 2007 2:17 AM (in response to grettke_spdr)Also note that system transactions and conversations are not related in a Seam application. These are independent contexts with a quite different scope. System transactions are short, conversations are potentially long-running and spanning several requests.
-
3. Re: What is the difference between EJB and POJO transactions
grettke_spdr Apr 22, 2007 3:27 PM (in response to grettke_spdr)"christian.bauer@jboss.com" wrote:
Also note that system transactions and conversations are not related in a Seam application. These are independent contexts with a quite different scope. System transactions are short, conversations are potentially long-running and spanning several requests.
Suppose that you have a conversation and you don't want to persist your changes until that conversation has ended. I believe this is the default behavior.
How is this behavior related to transactions? -
4. Re: What is the difference between EJB and POJO transactions
christian.bauer Apr 22, 2007 3:50 PM (in response to grettke_spdr)It's not the default behavior. The default behavior is to flush a persistence context (translation: dirty check objects, generate and execute SQL DML) when a transaction commits.
If you use Hibernate as your JPA provider, you can enable FlushModeType.MANUAL when you begin a conversation, so that the persistence context bound to that conversation is only flushed when you call entityManager.flush().
Please also read the Seam documentation, I'm basically quoting verbatim. -
5. Re: What is the difference between EJB and POJO transactions
statelessbean Apr 23, 2007 3:26 AM (in response to grettke_spdr)"christian.bauer@jboss.com" wrote:
It's not the default behavior. The default behavior is to flush a persistence context (translation: dirty check objects, generate and execute SQL DML) when a transaction commits.
If you use Hibernate as your JPA provider, you can enable FlushModeType.MANUAL when you begin a conversation, so that the persistence context bound to that conversation is only flushed when you call entityManager.flush().
Please also read the Seam documentation, I'm basically quoting verbatim.
What U mean Christian, in EJB U can also disable auto flush and set to manual.
in persistence.xml -
6. Re: What is the difference between EJB and POJO transactions
christian.bauer Apr 23, 2007 4:10 AM (in response to grettke_spdr)EJB 3.0 does not support disabling automatic flushing of the persistence context. This was one of the questionable changes forced into the specification by certain experts. The PC is always flushed automatically if there is a commit, the only way to prevent it is complicated auto commit mode.
Or the Hibernate setting that is also available in Seam. As soon as other JPA providers also add this essential feature, Seam will support that too. -
7. Re: What is the difference between EJB and POJO transactions
asavitsky Apr 23, 2007 10:12 AM (in response to grettke_spdr)"christian.bauer@jboss.com" wrote:
I recommend the last option, since it works with whatever components you execute and it is good from a scalability perspective. Also, you don't need to write any code or use any annotations with it.
Now that I've read the bold part, I'm a bit confused about the relationship between @Transactional and TransactionalSeamPhaseListener (I thought that I need both). Do you mean, that if I use the TransactionalSeamPhaseListener, I don't need to mark my POJOs with @Transactional at all?
Thanks,
Alex -
8. Re: What is the difference between EJB and POJO transactions
christian.bauer Apr 23, 2007 11:42 AM (in response to grettke_spdr)Javadoc of @Transactional:
/**
* Specifies that the transaction propagation for a JavaBean
* component or method of a JavaBean component. JavaBean
* components have @Transactional(SUPPORTS) behavior
* is no @Transactional annotation is specified.
*
* @author Gavin King
*/
SUPPORTS means that they will happily join whatever transaction is going on already, someone else started it. Which is the job of the TransactionalPhaseListener. -
9. Re: What is the difference between EJB and POJO transactions
christian.bauer Apr 23, 2007 11:44 AM (in response to grettke_spdr)Maybe what is also interesting is this:
/**
* The transaction propagation type.
*
* @return REQUIRED by default
*/
TransactionPropagationType value() default TransactionPropagationType.REQUIRED;
So if you just put @Transactional() on a bean or a method, it means Seam will actually start a transaction if none is active. That wouldn't happen if you have the right phase listener. -
10. Re: What is the difference between EJB and POJO transactions
grettke_spdr May 8, 2007 3:34 PM (in response to grettke_spdr)I have found that one ought to have already read 'Java Persistence with Hibernate' before reading about Seam. One needs to understand Hibernate/JPA before reading the Seam book, or documentation.
-
11. Re: What is the difference between EJB and POJO transactions
christian.bauer May 8, 2007 4:01 PM (in response to grettke_spdr)Actually, you only need to know a bit about EJB/CMT (EJB 2.x is good enough) and about JTA. Unfortunately, these days many developers think that "Spring transactions" are more important than the standards.