Dependency injection issue with EntityManagerFactory + jpadaosupport

I am currently having a problem injecting entityFactoryManager into my extended jpadaosupport class.

My configuration is below:

<bean id="productDao" class="springapp.repository.JdbcProductDao">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

The above configuration for this bean works fine, but when I try to use annotations to configure the bean, my application does not work

My JdbcProductDao.java file is below

@Repository("productDao")
@Transactional
public class JdbcProductDao extends JpaDaoSupport implements ProductDao {

    @SuppressWarnings("unchecked")
    @Override
    public List<Product> getProductList() {
        // TODO Auto-generated method stub
        return getJpaTemplate().getEntityManagerFactory().createEntityManager()
                .createQuery("from Product").getResultList();
    }

    @Override
    public void persist(Product product) {
        // TODO Auto-generated method stub

    }

    @Override
    public void saveProduct(Product prod) {
        // TODO Auto-generated method stub
        getJpaTemplate().merge(prod);
    }

    @Autowired
    @Required
    public void setJpaEntityManagerFactory(
            @Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
        super.setEntityManagerFactory(entityManagerFactory);
    }
}

However, it seems that EntityManagerFactory is not being entered properly, because none of the transactions in my database are visible

Can anyone suggest any kind of understanding?

+2
source share
5 answers

Pascal , , .

, :

  • JpaDaoSupport, JpaTemplate.
  • EntityManager, @PersistenceContext JpaDaoSupport

createEntityManager() spring. , EntityManager, . , 2 EntityManager - , - .

+1

bean?

    <context:component-scan base-package="com.noisyair.whatisayis.web"/>

spring .

+2

@Transactional, , <tx:annotation-driven/> Spring?

. 9.5.6. @Transactional 9, .

+2

?

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
+1

? , .

? " ", , INSERTING, ?

?

, ?

Make sure your CLASSPATH has a Log4J JAR and config XML. I find that Spring pumps a huge amount of information in the console at startup. You should see that it is better to understand what is happening. Make sure the application context finds your beans. There will be a lot of other useful information. Without it, you fly blindly.

0
source

Source: https://habr.com/ru/post/1761321/


All Articles