Announcement Announcement Module
Collapse
No announcement yet.
Hibernate, Eclipselink, spring 3 and jboss Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate, Eclipselink, spring 3 and jboss

    Our project is involved in migrating from hibernate to eclipselink and we are following a phased approach in doing this wherein some of the DAOs would be converted to eclipselink to start with and then slowly all of the DAOs would be migrated. We have a beanRef which brings up a shared application context (shared between the ejbs and the wars) and we bring up the entity managers in that. This works fine for reads in both hibernate and eclipselink . When persisting though hibernate entitymanager is persisting appropriately whereas the eclipselink one is not and is throwing exceptions. we use spring 3 , jboss 5.1.0 , eclipselink 2.3.2 in our project.

    The problem that we are having is that when we are trying to persist in an eclipselinkdao we get the exception
    Exception Description: No transaction is currently active
    15:53:30,248 ERROR [STDERR]:156 at org.eclipse.persistence.internal.jpa.transaction.E ntityTransactionWrapper.throwCheckTransactionFaile dException(EntityTransactionWrapper.java:113)
    15:53:30,248 ERROR [STDERR]:156 at org.eclipse.persistence.internal.jpa.transaction.E ntityTransactionWrapper.checkForTransaction(Entity TransactionWrapper.java:50)
    15:53:30,249 ERROR [STDERR]:156 at org.eclipse.persistence.internal.jpa.EntityManager Impl.checkForTransaction(EntityManagerImpl.java:17 76)
    15:53:30,249 ERROR [STDERR]:156 at org.eclipse.persistence.internal.jpa.EntityManager Impl.flush(EntityManagerImpl.java:780)
    15:53:30,266 ERROR [STDERR]:156 at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    15:53:30,279 ERROR [STDERR]:156 at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    15:53:30,280 ERROR [STDERR]:156 at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    15:53:30,281 ERROR [STDERR]:156 at java.lang.reflect.Method.invoke(Method.java:597)
    15:53:30,281 ERROR [STDERR]:156 at org.springframework.orm.jpa.ExtendedEntityManagerC reator$ExtendedEntityManagerInvocationHandler.invo ke(ExtendedEntityManagerCreator.java:365)

    Following is our spring setup.. We use two entity manager factories - one for hibernate and another for eclipselink and we use jta transaction since the dao will be called by a stateless session bean in jboss 5.1.0 server.

    in the spring config.xml we have the 2 of them as follows
    The hibernate one is as follows
    <bean id="hibEntityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="dataSource" ref="basicDataSource" />
    <property name="persistenceUnitName" value="PU1" />
    <property name="persistenceXmlLocation" value="classpath*:META-INF/persistencepu1.xml" />
    <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <property name="showSql" value="true" />
    </bean>
    </property>
    <property name="jpaPropertyMap">
    <map>
    <entry key="hibernate.current_session_context_class" value="jta" />
    <entry key="hibernate.transaction.manager_lookup_class"
    value="org.hibernate.transaction.JBossTransactionM anagerLookup" />
    <entry key="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFac tory" />
    <!-- DEBUG: Show and print nice SQL on stdout -->

    </map>
    </property>
    </bean>


    the one for eclipselink is as follows
    <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="dataSource" ref="basicDataSource" />
    <property name="persistenceUnitName" value="pu2" />
    <property name="jpaDialect" ref="eclipseLinkDialect" />
    <property name="persistenceXmlLocation"
    value="classpath:META-INF/eclipse-local.xml" />
    <property name="jpaVendorAdapter">
    <bean
    class="org.springframework.orm.jpa.vendor.EclipseL inkJpaVendorAdapter">
    <property name="showSql" value="true" />
    </bean>
    </property>

    <property name="jpaPropertyMap">
    <map>
    <entry key="eclipselink.weaving" value="false" />
    <entry key="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSess ionLog" />
    <entry key="eclipselink.logging.level" value="FINE" />
    <entry key="eclipselink.orm.throw.exceptions" value="true" />
    <entry key="eclipselink.logging.exceptions" value="true" />
    </map>
    </property>
    </bean>

    transaction manager is defined as follows

    <tx:jta-transaction-manager />


    is how we have defined our transaction manager so that we could use the container provided transaction manager . Both our persistence units have all the necessary classes and datasources properly defined and since it works for get for both hibernate and eclipselink i dont think that any of those setup is faulty.

    One of our baseeclipselinkdao has

    @PersistenceContext(unitName="pu2")
    protected EntityManager entityManager = null ;


    protected EntityManager getEntityManager() throws DAOException
    {
    return entityManager;
    }

    public <T extends PersistableObject> T createOrUpdateObject(T object) throws DAOException
    {
    try
    {
    EntityManager emgr = getEntityManager() ;
    handlePropertyChange(object);
    adjustCreatedModified(object) ;
    object = (T) emgr.merge(object) ;
    emgr.flush();
    return object ;

    }
    catch (PersistenceException e)
    {
    e.printStackTrace() ;
    throw new DAOException(e.getMessage()) ;
    }
    }


    and when it is flushing we are getting the above mentioned exception - "Exception Description: No transaction is currently active."

    It looks like the eclipselink entity manager is not able to get the transaction whereas the hibernate entity manager is able to get it . (it also explains why read works for both).Is there any configuration that I am missing for eclipselink ..

    Also i couldnt find an equivalent of
    <entry key="hibernate.current_session_context_class" value="jta" />
    <entry key="hibernate.transaction.manager_lookup_class"
    value="org.hibernate.transaction.JBossTransactionM anagerLookup" />
    <entry key="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFac tory" />

    properties in eclipselink. Could that be the problem?

    Please help me ..

  • #2
    Alternatively if someone has experience in having an eclipselink entitymanagerfactory configured to use jta in a jboss setting (5.1.0) that would help too..please let me know what should be the spring configuration that we need to use in such a case..

    Comment


    • #3
      Found the issue .. in my jpaPropertymap i was not passing in

      <entry key="eclipselink.target-server" value="JBoss"/>

      so with the above configuration if i use

      <property name="jpaPropertyMap">
      <map>
      <entry key="eclipselink.weaving" value="false" />
      <entry key="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSess ionLog" />
      <entry key="eclipselink.logging.level" value="FINE" />
      <entry key="eclipselink.orm.throw.exceptions" value="true" />
      <entry key="eclipselink.logging.exceptions" value="true" />
      <entry key="eclipselink.target-server" value="JBoss"/>
      </map>
      </property>

      then everything else being the same it worked..

      Comment

      Working...
      X