Announcement Announcement Module
Collapse
No announcement yet.
entityManager null. integrating JPA with Spring 3 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • entityManager null. integrating JPA with Spring 3

    This forum has helped a lot, but I have this problem my EntityManager is coming null
    ask help from masters
    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans" 
           xmlns:security="http://www.springframework.org/schema/security"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="
                  http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
                   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                               http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
                               http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">


       <!-- enabling annotation driven configuration /-->
    <context:annotation-config/>
    <context:component-scan base-package="br.com.agile2.beinfo.DAO.*"/>
       <tx:annotation-driven />

    <bean
           class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
     
        <bean id="dataSourcePG"
           class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://database.beinfo.agile:5432/foodmart" />
        <property name="username" value="root" />
        <property name="password" value="root" />      
           
           </bean>
     
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
            <qualifier value="transactionManager" />
         </bean>
     
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSourcePG" />
        <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
            <property name="persistenceUnitName" value="saikuPU"></property>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="false" />
                <property name="generateDdl" value="false" />
                <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
            </bean>
        </property>
        </bean>    
            <bean id="objetoItemDAO" class="br.com.agile2.beinfo.DAO.ObjetoItemDAO"/>
            <bean id="genericDAO" class="br.com.agile2.beinfo.DAO.GenericDAO"/>
            <bean id="usuarioDAO" class="br.com.agile2.beinfo.DAO.UsuarioDAO"/>
            <bean id="autenticationDAO" class="br.com.agile2.beinfo.DAO.AutenticationDAO"/>


        <context:annotation-config />

        <security:global-method-security secured-annotations="enabled">
        </security:global-method-security>
     
      
      <!-- BASIC AUTHENTICATION -->

        <security:http auto-config='true' access-denied-page="/login.jsp">
            <security:intercept-url pattern="/serverdocs/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
            <security:intercept-url pattern="/rest/saiku/session*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
            <security:intercept-url pattern="/rest/saiku/session/" access="IS_AUTHENTICATED_ANONYMOUSLY" />
            <security:intercept-url pattern="/rest/**" access="IS_AUTHENTICATED_FULLY" />
            <security:intercept-url pattern="/json/**" access="IS_AUTHENTICATED_FULLY" />
            <security:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />    
            <security:logout logout-url="/logout"/>  
            <security:http-basic/>
      
        </security:http>
        <import resource="applicationContext-spring-security.xml"/>
        <security:authentication-manager alias="authenticationManager">
            <security:authentication-provider user-service-ref='userDetailsService'>
                  <security:password-encoder ref="passwordEncoder" />
            </security:authentication-provider>
            
        </security:authentication-manager>
          

        
    </beans>
    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0" 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_2_0.xsd">
        <persistence-unit name="saikuPU" transaction-type="RESOURCE_LOCAL">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <class>br.com.agile2.beinfo.model.Usuario</class>
            <class>br.com.agile2.beinfo.model.Permissao</class>
            <class>br.com.agile2.beinfo.model.Consulta</class>
            <class>br.com.agile2.beinfo.model.Dashboard</class>
            <class>br.com.agile2.beinfo.model.ObjetoItem</class>
            <class>br.com.agile2.beinfo.model.UsuarioDashboard</class>
            <class>br.com.agile2.beinfo.model.UsuarioObjeto</class>
            <class>br.com.agile2.beinfo.model.DashboardConsulta</class>
            <class>br.com.agile2.beinfo.model.Consulta2</class>
            <properties>
               
    <!--            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://database.beinfo.agile:5432/foodmart"/>
                <property name="javax.persistence.jdbc.password" value="root"/>
                <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
                <property name="javax.persistence.jdbc.user" value="root" />
                <property name="javax.persistence.jdbc.show_sql" value="true" /> -->
    <!--            <property name="eclipselink.logging.logger" value="JavaLogger"/>
                <property name="eclipselink.logging.level.sql" value="FINEST" />
                <property name="eclipselink.logging.level" value="FINEST" />
                <property name="current_session_context_class" value="thread"/>  -->
                <property name="hibernate.hbm2ddl.auto" value="create"/>
                
            </properties>
        </persistence-unit>
    </persistence>
    PHP Code:
    package br.com.agile2.beinfo.DAO;

    import br.com.agile2.beinfo.Util.JpaUtil;
    import br.com.agile2.beinfo.model.Usuario;
    import java.io.Serializable;
    import java.util.*;
    import java.util.Map.Entry;
    import javax.persistence.*;
    import javax.persistence.criteria.CriteriaQuery;
    import org.springframework.stereotype.Repository;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    @
    Repository
    abstract class GenericDAO<T> implements Serializable {

        private static final 
    long serialVersionUID 1L;
        
        @
    PersistenceContext(unitName="saikuPU"type=PersistenceContextType.EXTENDED)
        
    EntityManager entityManager;

        
        public 
    void setEntityManager(EntityManager entityManager) {
        
    this.entityManager entityManager;
        }
        
        
        public Class<
    TentityClass;
      
        public 
    GenericDAO(Class<TentityClass) {
            
    this.entityClass entityClass;
            
        }

        
        
    // Using the unchecked because JPA does not have a
        // em.getCriteriaBuilder().createQuery()<T> method
        
    @SuppressWarnings({"unchecked""rawtypes"})
        @
    Transactional
        
    public List<TfindAll() {
            
    CriteriaQuery cq =  entityManager.getCriteriaBuilder().createQuery();
            
    cq.select(cq.from(entityClass));
            List<
    TentityList =  entityManager.createQuery(cq).getResultList();
            return 
    entityList;
        }
      

Working...
X