Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » GlassFish, Spring, Eclipselink EntityManager
GlassFish, Spring, Eclipselink EntityManager [message #546971] Wed, 14 July 2010 18:50 Go to next message
Fericit Bostan is currently offline Fericit BostanFriend
Messages: 68
Registered: June 2010
Member
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 17:13 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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>


James : Wiki : Book : Blog : Twitter
Re: GlassFish, Spring, Eclipselink EntityManager [message #547155 is a reply to message #547149] Thu, 15 July 2010 17:28 Go to previous messageGo to next message
Fericit Bostan is currently offline Fericit BostanFriend
Messages: 68
Registered: June 2010
Member
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] Mon, 30 September 2013 03:14 Go to previous messageGo to next message
Fadhel Ghorbel is currently offline Fadhel GhorbelFriend
Messages: 1
Registered: September 2013
Junior Member
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 19:31 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Please include your persistence.xml, ensure you are setting the "eclipselink.target-server"="Glassfish"

James : Wiki : Book : Blog : Twitter
Previous Topic:Bug for replication partition policy in XML configuration
Next Topic:Where is EclipseLink 2.5 XSD?
Goto Forum:
  


Current Time: Thu Mar 28 21:02:40 GMT 2024

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

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

Back to the top