Hey guys,
I've implemented an EJB3/JPA web service without any major problems, and now I've moved on a Spring-WS/JPA web service. Both are being deployed to Glassfish.
My understanding of JPA is limited, but by default transactions are container managed? How do you change this? With EJB3 things were straight forward as I could just inject the EntityManager in to the "DAO" (a discussion for another time!) with @PersistentConext and the container would take care of transaction demarcation. In terms of basic configuration that's about it. As the container uses JTA then I've specified the transaction type "JTA" on the persistence unit. In my very simple example application with one persistence unit I do not have to care about its name - Do things get more complicated if you have multiple persistence units or will the container take care of this?
Now I've built an equivelent web service with Spring-WS and have reused my entities/dao's, but I've struggled to get it working. I've included in my application context a bean definition for the EntityManagerFactory
(LocalContainerEntityManagerFactoryBean
) as well as for the JpaTransationManager
(bean reference to EntityManagerFactory
). I've also included the PersistenceAnnotationBeanPostProcessor
and the tx
namespace. I wouldn't have thought I'd need to do anything else but it wont deploy with a No persistence providers available for "null" error.
Do I need to specify the actual persistence unit I want to create a manager for?
Thanks,
Update:
Ok, I'm getting the following error: javax.persistence.PersistenceException: No Persistence provider for EntityManager named null.
It's probably my spring configuration for the factory/manager:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManager" />
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<tx:annotation-driven/>
I think I may need or inject something else in to it...
Another update:
Fixed that issue - Was using the LocalEntityManager instead of LocalContainerEntityManager.
Now I'm having problems persisting my objects. I have a parent object with a child object as a property. I can see the child object being persisted in the logs when I call em.persist(parent), but the parent doesn't get persisted.
Last update:
The parent object was getting persisted, but the transaction had not committed before I tried to retrieve it (I'm mocking without mocking so to speak). Think I've got the jist of it now.