Results 1 to 8 of 8
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,139
    Rep Power
    13

    Default Injection not working!

    I need some help here, Injection not working!
    I am missing something (getting a null pointer for the entityManager)

    The spring entry point, web.xml

    Java Code:
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
        <display-name>score progress</display-name>
       <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring.xml</param-value>
        </context-param>
    
    	
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    	
    	<filter>
    		<filter-name>struts2</filter-name>
    		<filter-class>
                    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
            </filter-class>
    	</filter>
    	
    	<filter-mapping>
    		<filter-name>struts2</filter-name>
    		<url-pattern>/*</url-pattern>
    	</filter-mapping>
    	
    	<welcome-file-list>
        	<welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    	
    </web-app>
    The mayor spring.xml (after resolving I will split this file into two)

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:jee="http://www.springframework.org/schema/jee"
           
           xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop-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/tx 
           	   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          	   http://www.springframework.org/schema/jee 
           	   http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"
    	  	default-lazy-init="true" default-autowire="byName">
    	
    		<context:component-scan base-package="com.canteratech.scoreprogress" />
    		 
    		<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager" />
    	
    	
    	<import resource="classpath:scoreprogress-spring-core.xml" />
            <!--
    	<import resource="scoreprogress-spring/jpa.xml" />
    	-->
    	
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    	    <property name="url" value="jdbc:mysql://localhost:3306/scoreprogress"/>
    	    <property name="username" value="root"/>
    	    <property name="password" value=""/>
    	</bean>
    
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource"/>
    		
    		<property name="persistenceUnitName" value="scoreprogress-jpa"/>
    		
    		<property name="jpaDialect">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
     		</property>
          		<property name="jpaVendorAdapter">
            			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
          		</property>
          		<!-- 
          		<property name="packagesToScan" value="com.canteratech.scoreprogress" />
          		-->
          		<property name="jpaProperties">
            		<props>
    					<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
    				</props>
          		</property>
       	</bean>
        
    	<tx:annotation-driven/>
    	<!--  
    	<tx:annotation-driven transaction-manager="transactionManager" />
    	-->
    	<bean class="org.springframework.orm.jpa.JpaTransactionManager"
    		id="transactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
    	
        <bean id="persistenceAnnotation" class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
     	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
     	
     	<bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
        	<property name="entityManagerFactory" ref="entityManagerFactory"/>
    	</bean> 
    
    </beans>
    and finally the entityManger injection (which turns out to be null)

    Java Code:
    @Component(value = "userDao")
    public class UserDaoImpl implements UserDao {
    	
    	@Autowired
    	//@PersistenceContext(name="dataSource")
        protected EntityManager entityManager;
    	….
    Last edited by willemjav; 04-16-2015 at 10:51 PM.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Injection not working!

    Your persistence unit name is ''scoreprogress-jpa', not 'dataSource'.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,139
    Rep Power
    13

    Default Re: Injection not working!

    thanks gimbal2
    still null pointing....
    btw I commented that "scoreprogress-jpa" see #1
    prefere to use @Autowired, but still not injecting!

    the "scoreprogress-jpa" was pointing to a persistence.xml,
    which I am not using currently, should I?
    Last edited by willemjav; 04-16-2015 at 06:10 PM.

  4. #4
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,139
    Rep Power
    13

    Default Re: Injection not working!

    The next code is the imported resources of line 26 of the spring.xml

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns="http://www.springframework.org/schema/beans"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-3.0.xsd"
    		default-lazy-init="true" default-autowire="byName">
    	
    	<!-- Scan classes -->
    	<context:component-scan base-package="com.canteratech.scoreprogress" />
    	
    </beans>
    The above code is at the core package of the application.
    The application has two modulus: cor and web

    Java Code:
    <modules>
    	<module>core</module>
    	<module>web</module>
      </modules>
    Sure, the UserDaoImpl is at the core part!
    But all is included in:
    <context:component-scan base-package="com.canteratech.scoreprogress" />
    or should I say:
    <context:component-scan base-package="com.canteratech.scoreprogress.appservice" />
    Last edited by willemjav; 04-16-2015 at 11:25 PM.

  5. #5
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,139
    Rep Power
    13

    Default Re: Injection not working!

    The persistence.xml which was missing

    Java 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="scoreprogress-jpa" transaction-type="RESOURCE_LOCAL">
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
    	<!-- 
    		<properties>
                <property name="hibernate.hbm2ddl.auto" value="validate" />
    		</properties>
    	 -->
    	</persistence-unit>
    </persistence>

  6. #6
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,139
    Rep Power
    13

    Default Re: Injection not working!

    The revised version spring.xml

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:jee="http://www.springframework.org/schema/jee"
           
           xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop-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/tx 
           	   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          	   http://www.springframework.org/schema/jee 
           	   http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"
    	  	default-lazy-init="true" default-autowire="byName">
    	
    		<context:component-scan base-package="com.canteratech.scoreprogress" />
    		 
    		<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager" />
    	
    		<import resource="classpath:scoreprogress-spring-core.xml" />
    		
    		
    		<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    			<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    		    <property name="url" value="jdbc:mysql://localhost:3306/scoreprogress"/>
    		    <property name="username" value="root"/>
    		    <property name="password" value=""/>
    		</bean>
    	
    	    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    			<property name="dataSource" ref="dataSource"/>
    			
    			<property name="persistenceUnitName" value="scoreprogress-jpa" />
    			
    			<property name="jpaDialect">
    				<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
    	 		</property>
    	      	<property name="jpaVendorAdapter">
    	        		<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    	      	</property>
    	      
    	      	<property name="jpaProperties">
    	        		<props>
    					<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
    					<prop key="hibernate.hbm2ddl.auto">validate</prop>
    					<prop key="hibernate.format_sql">true</prop>
    				</props>
    	      	</property>
       	</bean>
        
    	<tx:annotation-driven/>
    
         <bean id="persistenceAnnotation" class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
     	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
     	
     	<bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
        	<property name="entityManagerFactory" ref="entityManagerFactory"/> 
    	</bean> 
    
    </beans>

    and the persistence.xml

    Java 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="scoreprogress-jpa" transaction-type="RESOURCE_LOCAL">
    	       <provider>org.hibernate.ejb.HibernatePersistence</provider>
    	</persistence-unit>
    </persistence>
    Last edited by willemjav; 04-18-2015 at 10:23 AM.

  7. #7
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,139
    Rep Power
    13

    Default Re: Injection not working!

    which gives my the next error:

    Apr 18, 2015 9:05:54 AM org.springframework.web.context.support.XmlWebAppl icationContext refresh
    WARNING: Exception encountered during context initialization - cancelling refresh attempt
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: scoreprogress-jpa] Unable to build Hibernate SessionFactory
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1574)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:3 03)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:230)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:299 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:956)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:747)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:480)
    at org.springframework.web.context.ContextLoader.conf igureAndRefreshWebApplicationContext(ContextLoader .java:403)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 106)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:4760)
    at org.apache.catalina.core.StandardContext.startInte rnal(StandardContext.java:5184)
    at org.apache.catalina.util.LifecycleBase.start(Lifec ycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild. call(ContainerBase.java:1396)
    at org.apache.catalina.core.ContainerBase$StartChild. call(ContainerBase.java:1386)
    at java.util.concurrent.FutureTask.run(FutureTask.jav a:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: javax.persistence.PersistenceException: [PersistenceUnit: scoreprogress-jpa] Unable to build Hibernate SessionFactory
    at org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl.persistenceException(EntityManagerFa ctoryBuilderImpl.java:874)
    at org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl.build(EntityManagerFactoryBuilderImp l.java:802)
    at org.springframework.orm.jpa.vendor.SpringHibernate JpaPersistenceProvider.createContainerEntityManage rFactory(SpringHibernateJpaPersistenceProvider.jav a:60)
    at org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean.createNativeEntityManagerFactory( LocalContainerEntityManagerFactoryBean.java:343)
    at org.springframework.orm.jpa.AbstractEntityManagerF actoryBean.afterPropertiesSet(AbstractEntityManage rFactoryBean.java:318)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1633)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1570)
    ... 21 more
    Caused by: java.lang.ClassCastException: java.util.Collections$EmptyIterator cannot be cast to java.lang.Iterable
    at org.hibernate.tool.schema.extract.internal.Sequenc eInformationExtractorNoOpImpl.extractMetadata(Sequ enceInformationExtractorNoOpImpl.java:45)
    at org.hibernate.tool.schema.extract.internal.legacy. DatabaseInformationImpl.initializeSequences(Databa seInformationImpl.java:99)
    at org.hibernate.tool.schema.extract.internal.legacy. DatabaseInformationImpl.<init>(DatabaseInformation Impl.java:95)
    at org.hibernate.tool.hbm2ddl.SchemaValidator.validat e(SchemaValidator.java:97)
    at org.hibernate.internal.SessionFactoryImpl.<init>(S essionFactoryImpl.java:459)
    at org.hibernate.boot.internal.SessionFactoryBuilderI mpl.build(SessionFactoryBuilderImpl.java:151)
    at org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl.build(EntityManagerFactoryBuilderImp l.java:799)
    ... 26 more

    Apr 18, 2015 9:05:54 AM org.springframework.web.context.ContextLoader initWebApplicationContext
    SEVERE: Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: scoreprogress-jpa] Unable to build Hibernate SessionFactory
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1574)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:3 03)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:230)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:299 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:956)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:747)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:480)
    at org.springframework.web.context.ContextLoader.conf igureAndRefreshWebApplicationContext(ContextLoader .java:403)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 106)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:4760)
    at org.apache.catalina.core.StandardContext.startInte rnal(StandardContext.java:5184)
    at org.apache.catalina.util.LifecycleBase.start(Lifec ycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild. call(ContainerBase.java:1396)
    at org.apache.catalina.core.ContainerBase$StartChild. call(ContainerBase.java:1386)
    at java.util.concurrent.FutureTask.run(FutureTask.jav a:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: javax.persistence.PersistenceException: [PersistenceUnit: scoreprogress-jpa] Unable to build Hibernate SessionFactory
    at org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl.persistenceException(EntityManagerFa ctoryBuilderImpl.java:874)
    at org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl.build(EntityManagerFactoryBuilderImp l.java:802)
    at org.springframework.orm.jpa.vendor.SpringHibernate JpaPersistenceProvider.createContainerEntityManage rFactory(SpringHibernateJpaPersistenceProvider.jav a:60)
    at org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean.createNativeEntityManagerFactory( LocalContainerEntityManagerFactoryBean.java:343)
    at org.springframework.orm.jpa.AbstractEntityManagerF actoryBean.afterPropertiesSet(AbstractEntityManage rFactoryBean.java:318)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1633)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1570)
    ... 21 more
    Caused by: java.lang.ClassCastException: java.util.Collections$EmptyIterator cannot be cast to java.lang.Iterable
    at org.hibernate.tool.schema.extract.internal.Sequenc eInformationExtractorNoOpImpl.extractMetadata(Sequ enceInformationExtractorNoOpImpl.java:45)
    at org.hibernate.tool.schema.extract.internal.legacy. DatabaseInformationImpl.initializeSequences(Databa seInformationImpl.java:99)
    at org.hibernate.tool.schema.extract.internal.legacy. DatabaseInformationImpl.<init>(DatabaseInformation Impl.java:95)
    at org.hibernate.tool.hbm2ddl.SchemaValidator.validat e(SchemaValidator.java:97)
    at org.hibernate.internal.SessionFactoryImpl.<init>(S essionFactoryImpl.java:459)
    at org.hibernate.boot.internal.SessionFactoryBuilderI mpl.build(SessionFactoryBuilderImpl.java:151)
    at org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl.build(EntityManagerFactoryBuilderImp l.java:799)
    ... 26 more

    Apr 18, 2015 9:05:54 AM org.apache.catalina.core.StandardContext listenerStart
    SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListe ner
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: scoreprogress-jpa] Unable to build Hibernate SessionFactory
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1574)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:3 03)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:230)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:299 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:956)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:747)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:480)
    at org.springframework.web.context.ContextLoader.conf igureAndRefreshWebApplicationContext(ContextLoader .java:403)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 106)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:4760)
    at org.apache.catalina.core.StandardContext.startInte rnal(StandardContext.java:5184)
    at org.apache.catalina.util.LifecycleBase.start(Lifec ycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild. call(ContainerBase.java:1396)
    at org.apache.catalina.core.ContainerBase$StartChild. call(ContainerBase.java:1386)
    at java.util.concurrent.FutureTask.run(FutureTask.jav a:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: javax.persistence.PersistenceException: [PersistenceUnit: scoreprogress-jpa] Unable to build Hibernate SessionFactory
    at org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl.persistenceException(EntityManagerFa ctoryBuilderImpl.java:874)
    at org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl.build(EntityManagerFactoryBuilderImp l.java:802)
    at org.springframework.orm.jpa.vendor.SpringHibernate JpaPersistenceProvider.createContainerEntityManage rFactory(SpringHibernateJpaPersistenceProvider.jav a:60)
    at org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean.createNativeEntityManagerFactory( LocalContainerEntityManagerFactoryBean.java:343)
    at org.springframework.orm.jpa.AbstractEntityManagerF actoryBean.afterPropertiesSet(AbstractEntityManage rFactoryBean.java:318)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1633)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1570)
    ... 21 more
    Caused by: java.lang.ClassCastException: java.util.Collections$EmptyIterator cannot be cast to java.lang.Iterable
    at org.hibernate.tool.schema.extract.internal.Sequenc eInformationExtractorNoOpImpl.extractMetadata(Sequ enceInformationExtractorNoOpImpl.java:45)
    at org.hibernate.tool.schema.extract.internal.legacy. DatabaseInformationImpl.initializeSequences(Databa seInformationImpl.java:99)
    at org.hibernate.tool.schema.extract.internal.legacy. DatabaseInformationImpl.<init>(DatabaseInformation Impl.java:95)
    at org.hibernate.tool.hbm2ddl.SchemaValidator.validat e(SchemaValidator.java:97)
    at org.hibernate.internal.SessionFactoryImpl.<init>(S essionFactoryImpl.java:459)
    at org.hibernate.boot.internal.SessionFactoryBuilderI mpl.build(SessionFactoryBuilderImpl.java:151)
    at org.hibernate.jpa.boot.internal.EntityManagerFacto ryBuilderImpl.build(EntityManagerFactoryBuilderImp l.java:799)
    ... 26 more

    Apr 18, 2015 9:05:54 AM org.apache.catalina.core.StandardContext startInternal
    SEVERE: Error listenerStart
    Apr 18, 2015 9:05:54 AM org.apache.catalina.core.StandardContext startInternal
    SEVERE: Context [/scoreprogress] startup failed due to previous errors
    Apr 18, 2015 9:05:54 AM org.apache.catalina.core.ApplicationContext log
    INFO: Closing Spring root WebApplicationContext
    Apr 18, 2015 9:05:54 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
    WARNING: The web application [/scoreprogress] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
    Apr 18, 2015 9:05:54 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    WARNING: The web application [/scoreprogress] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
    java.lang.Object.wait(Native Method)
    java.lang.ref.ReferenceQueue.remove(ReferenceQueue .java:142)
    com.mysql.jdbc.AbandonedConnectionCleanupThread.ru n(AbandonedConnectionCleanupThread.java:40)
    Apr 18, 2015 9:05:54 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-nio-8080"]
    Apr 18, 2015 9:05:54 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["ajp-nio-8009"]
    Apr 18, 2015 9:05:54 AM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 13670 ms

  8. #8
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,139
    Rep Power
    13

    Default Re: Injection not working!

    okay resolved the error by changing the hibernates into
    <version>4.0.5.Final</version>

    no errors now but still having my null pointer, oh boy....

    At this point I know:
    1) the spring.xml will be read by the application
    2) there are no errors appearing

    Would that mean that all the beans are created successfully?
    More particular: I will have a full-armed entityManagerFactory, transactionManager
    and entityManager object to my disposal?

    Though when I try

    Java Code:
    @Component(value = "userDao")
    @Transactional
    public class UserDaoImpl implements UserDao {
    	
    	//@Autowired
    	@PersistenceContext(name="scoreprogress-jpa")
        protected EntityManager entityManager;
    
        public EntityManager getEntityManager() {
    		return entityManager;
    	}
    	public void setEntityManager(EntityManager entityManager) {
    		this.entityManager = entityManager;
    	}
    entityManager turns to be null
    Last edited by willemjav; 04-18-2015 at 04:52 PM.

Similar Threads

  1. What is SQL Injection
    By gilbertsavier in forum JDBC
    Replies: 0
    Last Post: 07-17-2009, 07:22 AM
  2. Replies: 0
    Last Post: 03-29-2008, 12:38 PM
  3. Replies: 0
    Last Post: 03-29-2008, 12:38 PM
  4. Replies: 0
    Last Post: 09-26-2007, 08:29 PM
  5. Replies: 0
    Last Post: 09-26-2007, 08:28 PM

Posting Permissions

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