hiclas
hiclas

Reputation: 41

Use HibernateCursorItemReader with Entitymanagerfactory

I'm trying to use HibernateCursorItemReader in my Spring batch (for an architectural reason, and I can't use JpaPagingItemReader because I don't need pagination). But, the problem is that I have to set the session factory and in my case I have only the entityManagerFactory. Unfortunetly, I have to use only an XML configuration for that purpose. I know that in Java code we can make conversion like that:

Session session = manager.unwrap(Session.class);
sessionFactory = session.getSessionFactory();

How can I set my sessionFactory property in my HibernateCursorItemReader? If I have to make conversion from entityManagerFactory to SessionFactory? how can I make it directly in an XML config?

Upvotes: 1

Views: 572

Answers (1)

hiclas
hiclas

Reputation: 41

The solution is to use the method: getSessionFactory of entityManagerFactory

    <bean id="hibernateSessionFactory" factory-bean="entityManagerFactory"
    factory-method="getSessionFactory" />

Upvotes: 1

Related Questions