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...
Where I would expect the setEntityManager to be called.PHP Code:public class HibernateGenericManager<T> {
protected Class<T> persistClass;
@PersistenceContext
protected EntityManager entityManager;
public HibernateGenericManager() {
this.persistClass = (Class<T>)((ParameterizedType)this.getClass()
.getGenericSuperclass()).getActualTypeArguments()[0];
}
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager ;
}
THIs is part of my applicationContext
and my persistence.xmlPHP 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" />
Does anything seem wrong?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>
Many thanks in advance.


Reply With Quote