hi,
since 3 days i'm trying to inject a EntityManager or EntityManagerFactory into my Dao to access the DB.
But the field is always null... and i have no idea whats the problem.
I tried it with @Autowired, with normal beans, and so on...
here's the current code from my applicationContext.xml:
and my LectureDaoImpl:Code:<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="generateDdl" value="true" /> <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> </bean> </property> <property name="persistenceUnitName" value="MontyBroganPU" /> <property name="dataSource" ref="dataSource" /> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/MontyBrogan"/> <property name="username" value="root"/> <property name="password" value="ganzgeheim"/> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"></property> <property name="dataSource" ref="dataSource"/> </bean> <tx:annotation-driven /> <context:annotation-config/> <context:component-scan base-package="DaoImpl"/> <!-- <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> --> <!-- <bean id="lectureDao" class="DaoImpl.LectureDaoImpl" /> -->
my persistence.xml has just the headerCode:@Repository public class LectureDaoImpl implements LectureDao { private EntityManagerFactory entityManagerFactory; @Autowired @PersistenceUnit(unitName = "MontyBroganPU") public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) { this.entityManagerFactory = entityManagerFactory; } @Transactional(readOnly = true) public List<Lecture> findAll() { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query query = entityManager.createQuery("from Lecture"); return query.getResultList(); }
and the error:Code:<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.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_1_0.xsd"> <persistence-unit name="MontyBroganPU"> </persistence-unit> </persistence>
please help meCode:09:39:33,339 ERROR [DispatcherPortlet:501] Could not complete request java.lang.NullPointerException at DaoImpl.LectureDaoImpl.findAll(LectureDaoImpl.java:53) at Controller.ViewController.handleRenderRequestInternal(ViewController.java:44) at org.springframework.web.portlet.mvc.AbstractController.handleRenderRequest(AbstractController.java:219) at org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter.handleRender(SimpleControllerHandlerAdapter.java:52) at org.springframework.web.portlet.DispatcherPortlet.doRenderService(DispatcherPortlet.java:811)![]()


Reply With Quote
