Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » GlassFish, Spring, Eclipselink EntityManager
GlassFish, Spring, Eclipselink EntityManager [message #546971] Wed, 14 July 2010 14:50 Go to next message
Eclipse UserFriend
I'm running in GlassFish 3.0.1 with EclipseLink 2.0 and Spring 3.0. I have a Stateless EJB that is also a WebService.
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Interceptors(SpringBeanAutowiringInterceptor.class)
@WebService(...)
@Service


My EJB calls into my Dao framework which is managed by Spring. I'm using Spring's JpaTemplate to provide Exception Translation. My Dao classes are defined as Transactional using Spring annotations. Also, to be able to inject an EntityManagerFactory into my Dao classes / JpaTemplate, I have to configure the Spring LocalContainerEntityManagerFactoryBean.

@Transactional(propagation = Propagation.REQUIRED)


And my Spring configuration is defined as follows:
    <tx:jta-transaction-manager />

    <tx:annotation-driven/>
  
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="jpaVendorAdapter">
            <bean
                class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
                <property name="showSql" value="true" />
            </bean>
        </property>
        <property name="jpaDialect">
            <bean
                class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
        </property>
        <property name="persistenceUnitName" value="my-pu"></property>
    </bean>    

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
        <property name="persistenceUnits">
            <map>
                <entry key="my-pu" value="persistence/survey-pu"/>
            </map>
        </property>
        <property name="persistenceContexts">
            <map>
                <entry key="my-pu" value="persistence/survey-pu"/>
            </map>
        </property>
    </bean>


My problem is that it appears that Transactions are not working correctly or as expected. When I perform a read for an object, if I perform the query a second time I get a different instance of the object. While the data is the same the objects are not. This tells me that each object is being read within a different transaction.

I'm struggling with getting the Container and Spring to play nicely with each other. I want my EntityManager to participate within a Global transaction that should be started by the container.

Has anyone ever tried this or been successful with getting these technologies playing together?

Thanks for the help...
Re: GlassFish, Spring, Eclipselink EntityManager [message #547149 is a reply to message #546971] Thu, 15 July 2010 13:13 Go to previous messageGo to next message
Eclipse UserFriend
I'm no Spring expert, but I think you need to define a JTA transaction managed.

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager ">
<property name="userTransaction" ref="glassfish" />
</bean>
Re: GlassFish, Spring, Eclipselink EntityManager [message #547155 is a reply to message #547149] Thu, 15 July 2010 13:28 Go to previous messageGo to next message
Eclipse UserFriend
Actually, the following annotation does that for you:
<tx:jta-transaction-manager/>

Re: GlassFish, Spring, Eclipselink EntityManager [message #1120857 is a reply to message #547155] Sun, 29 September 2013 23:14 Go to previous messageGo to next message
Eclipse UserFriend
Have you found a solution for your problem? I have the same problem.
Re: GlassFish, Spring, Eclipselink EntityManager [message #1121579 is a reply to message #1120857] Mon, 30 September 2013 15:31 Go to previous message
Eclipse UserFriend
Please include your persistence.xml, ensure you are setting the "eclipselink.target-server"="Glassfish"
Previous Topic:Bug for replication partition policy in XML configuration
Next Topic:Where is EclipseLink 2.5 XSD?
Goto Forum:
  


Current Time: Wed Jul 23 10:00:47 EDT 2025

Powered by FUDForum. Page generated in 0.12604 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top