Announcement Announcement Module
No announcement yet.
Using JPA based DAO in an Hibernate context? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using JPA based DAO in an Hibernate context?


    in a legacy application based 100% on Hibernate, we would like to be able to use some JPA based DAO coming from a shared component (and relying on Hibernate implementation)

    Everything seem to work fine with a jpaContext.xml and HibernateContext.xml definition side by side, but when it comes to transaction we get into trouble.

    We can do query, or any read-only operation, through the shared JPA DAO.
    But the system cannot find an open Transaction when it needs to persist a JPA Entity.

    The problem comes from the transactionManager. It seems there can only be one in use. We have one

    <bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
    but our
    <tx:annotation-driven transaction-manager="transactionManager"/>
    points to the Hibernate TX Manager.

    Is there any way to get this working without porting the whole application to JPA? Can't an EntityManager reuse a transaction opened by Hibernate?

  • #2
    I believe for reading data base transactions are optional (I may be incorrect here). so it is working for read operations
    But one thing looks incorrect here is
    <bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />

    <tx:annotation-driven transaction-manager="transactionManager"/>

    it should be "jpaTransactionManager"


    • #3
      That's precisely the thing: it's not a mistake, it needs to be this way, because the application is Hibernate based and has to use an Hibernate Transaction manager that uses a SessionFactory.

      I can't make the application use both Tx managers. It has to use the Hibernate one.
      But I need to be able to persist a JPA entity, managed by a JPA DAO.
      The problem I have is that the write operation can't find a transaction to operate.

      Is there a way to make EntityManagerFactory based operation use transaction opened by an Hibernate transaction manager?

      Or does anyone see an other way to mix EntityManagerFactory and SessionFactory base Dao operation?
      Last edited by Jean; Oct 30th, 2009, 03:01 AM.


      • #4
        hi Jean,

        Its jpaTranscationManager bean id you have defined above thats why I means....