Announcement Announcement Module
Collapse
No announcement yet.
SPring wll not inject EntityMAnager into my DAO Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 09:10 AM.

  • #2
    See if this link is helpful http://stackoverflow.com/questions/1...ersistence-xml

    Comment


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

      Comment

      Working...
      X