Announcement Announcement Module
No announcement yet.
Defining getting an object from bean in spring-context.xml Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Defining getting an object from bean in spring-context.xml

    Hi folk,

    the headline might sound a little bit odd, but here is my explaination. I like to use a part of JPA. The JPA- Implementation is provided by Hibernate. I want to use the Hibernate API in my DAO via HibernateDaoSupport, but want to define my domainobject with JPA.

    What I did was configuring a entityManagerFactory. This one I set into my DAO which extracts the SessionFactory for Hibernate an set it into the method of HiberateDaoSupport. Now I am able to use the HibernateTemplate instead of the JPATemplate. Because I like the much more powerful API of Hibernate than the one of JPA.

    Now I am stucked. I like to use the OpenSessionInViewInterceptor, what wants the SessionFactory be set in the spring-context.

    What I like to do is something like this:

    <bean id="entityManagerFactory" ....> .... </bean>
    <bean id="hibernateGenericDao" class=".....">
         <property name="entityMangerFactory" ref="entityMangerFactory"/>     
    <bean id="openSessionInViewFilter" class="....">
         <property name="sessionFactory" value="hibernateGenericDao.getSessionFactory"/>
    Anyone an idea?

    Thx in advance,


  • #2
    I suggest you either use the Hibernate API or JPA, but not both. If the former (which you and others say you prefer) then you don't want an EntityManagerFactory at all, but a SessionFactory.


    • #3

      thanks for your reply. I like to use JPA Annotation for my domainclasses, to provide a tool independent model. Also I like to use Hibernate for my current DAOs. In the future it could be another vendor. For this case I like to keep my domainmodel clean of tool specific code.

      Prove me when I am wrong, but if I use JPA Annotations I cannot use a SessionFactory from startup. I have to take the detour through an EntityMangerFactory. That leads to my problem.