Results 1 to 3 of 3

Thread: SPring wll not inject EntityMAnager into my DAO

  1. #1
    Join Date
    Jan 2011
    Posts
    3

    Default SPring wll not inject EntityMAnager into my DAO

    I am quite new to Spring and have been given the task of refactoring an existing application and this time using spring. The application is struts hibernate and the basic architecture is

    action -> service -> DAO -> Persistant Objects

    I have managed to get the services injecting into the action and the DAO injecting into the service but the EntityMAnager is not being injected into the DAO.

    THE DAO has a superclass...

    PHP Code:
    public class HibernateGenericManager<T>  {

        protected Class<
    TpersistClass;

           @
    PersistenceContext
        
    protected EntityManager entityManager;
        public 
    HibernateGenericManager() {
            
    this.persistClass = (Class<T>)((ParameterizedType)this.getClass()
                .
    getGenericSuperclass()).getActualTypeArguments()[0];
            
        }

        public 
    void setEntityManager(EntityManager entityManager) {
            
    this.entityManager entityManager ;

    Where I would expect the setEntityManager to be called.

    THIs is part of my applicationContext

    PHP Code:
        <bean id="entityManagerFactory"
            
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <
    property name="dataSource" ref="dataSource" />
            <
    property name="jpaVendorAdapter">
                <
    bean
                    
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <
    property name="database" value="MYSQL" />
                    <
    property name="showSql" value="true" />
                </
    bean>
            </
    property>
        </
    bean>
        
         <
    bean id="dataSource"
            
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <
    property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <
    property name="url" value="jdbc:mysql://127.0.0.1/football" />
            <
    property name="username" value="root" />
            <
    property name="password" value="&&&&&" />
        </
    bean>

        <
    bean id="transactionManager"
            
    class="org.springframework.orm.jpa.JpaTransactionManager">
            <
    property name="entityManagerFactory" ref="entityManagerFactory" />
        </
    bean>
        
        <
    bean
            
    class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 
    and my persistence.xml

    PHP Code:
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
        
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
        
    version="1.0">
        <
    persistence-unit name="punit">
        </
    persistence-unit>
    </
    persistence
    Does anything seem wrong?

    Many thanks in advance.
    Last edited by davidrocks; Jan 17th, 2011 at 08:10 AM.

  2. #2
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    287

    Default

    Amila Domingo

  3. #3

    Default

    Please post definition of your DAOs in the application context xml.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •