Announcement Announcement Module
Collapse
No announcement yet.
Defining getting an object from bean in spring-context.xml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

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


    Thx in advance,

    Danny

  • #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.

    Comment


    • #3
      Hi,

      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.

      Comment

      Working...
      X