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

  • Integrating Spring 3 with JPA entityManager = null

    I'm working on that with this integration time and am taking this bomb, remembering that I'm using spring security,
    Funny that the entityManager the login method is not null, the other methods are now null
    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 transaction-manager="transactionManager" proxy-target-class="true"/>

    <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:
    @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;
        } 
    Login DAO that is working (used spring security)

    PHP Code:
    @Repository
    public class AutenticationDAO  extends GenericDAO<Usuario>  implements UserDetailsService  {

        public 
    AutenticationDAO() {
            
    super(Usuario.class);
        }
        
        public 
    void authoritiesByUsernameQuery(String username){
            
        }
        
        public 
    Usuario loadUserByUsername(String usernamethrows UsernameNotFoundExceptionDataAccessException {
            
    Usuario entity entityManager.createNamedQuery("usuario.findByNomLogin"Usuario.class)  
                      .
    setParameter("nomLogin"username)  
                      .
    getSingleResult();
            return 
    entity;
        
        }

    This method is coming with entityManager = null

    PHP Code:
    @Repository
    public class UsuarioDAO extends GenericDAO<Usuario> {
        
        public 
    UsuarioDAO() {
            
    super(Usuario.class);
        }

        public List<
    UsuariofindAllUser(boolean indHabilitado){      
            
             List<
    UsuarioentityList entityManager.createNamedQuery("usuario.findByIndHabilitado"Usuario.class)  
                      .
    setParameter("indHabilitado"indHabilitado)  
                      .
    getResultList();
            return 
    entityList;
        } 
Working...
X