Re: Transactional web service using CXF, Spring and JPA
Yep, CXF has the invoker[1] to take care the whole invoking stuff. Jeff just showed you the basic use scenario which treats the implementor as a singleton in the default bean Invoker. All the client sides concurrency invocations will be end up in this singleton invoker, so we can still use the spring to transaction management here. [1]http://cwiki.apache.org/CXF20DOC/invokers.html Willem. Jeff Yu wrote: Hi, You need to delegate the transaction to spring, not the cxf. like: implementorClass="net.java.dev.service.MyServiceImpl" implementor="#myService" address="/theService"> ... here the "myService" is with transaction, with other spring-specific config to add transaction. Best Regards Jeff Karl Goldstein wrote: Greetings, I've been experimenting with creating a transactional web service using CXF, Spring and JPA/Hibernate. The basic examples I've seen of such services look like this: @Transactional @WebService(...) public class MyService implements MyServiceInterface { @PersistenceContext private EntityManager em; public void myOperation() throws DataAccessException { ... // use injected entity manager em.find(...) ... } } and the Spring config has this: ... Here's what I would expect to happen with a transactional web service based on JPA: - Request begins - System begins new unit of database work by creating a new EntityManager - All database interactions in the request use the same EntityManager - Request finishes processing - Transaction commits or rolls back (if an error occurred) - Response sent As far as I can tell, Spring is only creating one instance of my service bean, and injecting a single EntityManager into it when it does so. This clearly won't work when handling multiple concurrent requests, since EntityManager is not thread-safe and a new one needs to be instantiated for each unit of work. Is the above setup actually right? Can anyone point me to an example of how to wire this all together correctly? I'm about to give up on using Spring transactional support and go back to just implementing my own simple transactional wrapper and making the EntityManager available to DAOs through a ThreadLocal. Thanks, Karl __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: Transactional web service using CXF, Spring and JPA
Hi, You need to delegate the transaction to spring, not the cxf. like: implementorClass="net.java.dev.service.MyServiceImpl" implementor="#myService" address="/theService"> ... here the "myService" is with transaction, with other spring-specific config to add transaction. Best Regards Jeff Karl Goldstein wrote: Greetings, I've been experimenting with creating a transactional web service using CXF, Spring and JPA/Hibernate. The basic examples I've seen of such services look like this: @Transactional @WebService(...) public class MyService implements MyServiceInterface { @PersistenceContext private EntityManager em; public void myOperation() throws DataAccessException { ... // use injected entity manager em.find(...) ... } } and the Spring config has this: ... Here's what I would expect to happen with a transactional web service based on JPA: - Request begins - System begins new unit of database work by creating a new EntityManager - All database interactions in the request use the same EntityManager - Request finishes processing - Transaction commits or rolls back (if an error occurred) - Response sent As far as I can tell, Spring is only creating one instance of my service bean, and injecting a single EntityManager into it when it does so. This clearly won't work when handling multiple concurrent requests, since EntityManager is not thread-safe and a new one needs to be instantiated for each unit of work. Is the above setup actually right? Can anyone point me to an example of how to wire this all together correctly? I'm about to give up on using Spring transactional support and go back to just implementing my own simple transactional wrapper and making the EntityManager available to DAOs through a ThreadLocal. Thanks, Karl __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Transactional web service using CXF, Spring and JPA
Greetings, I've been experimenting with creating a transactional web service using CXF, Spring and JPA/Hibernate. The basic examples I've seen of such services look like this: @Transactional @WebService(...) public class MyService implements MyServiceInterface { @PersistenceContext private EntityManager em; public void myOperation() throws DataAccessException { ... // use injected entity manager em.find(...) ... } } and the Spring config has this: ... Here's what I would expect to happen with a transactional web service based on JPA: - Request begins - System begins new unit of database work by creating a new EntityManager - All database interactions in the request use the same EntityManager - Request finishes processing - Transaction commits or rolls back (if an error occurred) - Response sent As far as I can tell, Spring is only creating one instance of my service bean, and injecting a single EntityManager into it when it does so. This clearly won't work when handling multiple concurrent requests, since EntityManager is not thread-safe and a new one needs to be instantiated for each unit of work. Is the above setup actually right? Can anyone point me to an example of how to wire this all together correctly? I'm about to give up on using Spring transactional support and go back to just implementing my own simple transactional wrapper and making the EntityManager available to DAOs through a ThreadLocal. Thanks, Karl __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com