Spring - entitymanager / transaction
Hello...
I´m working with Spring Data JPA.
But because it is inflexible, I created a class
sô i could create dynamic query.
So, for that class I have an EntityManager instance.
And since I´m using hibernate´s criteria API, i do this:
Session hibernateSession = entityManager.unwrap(Session.class);
Criteria criteria = hibernateSession.createCriteria(entityClass);
but, at the very first line I receive an exception:
java.lang.IllegalStateException: No transactional EntityManager available
The class that receives entityManager and passes it through another class via constructor:
@PersistenceContext
private EntityManager entityManager;
//...
@PostConstruct
public void init(){
lazyModel = new BaseLazyModelJPA<Grupo, Integer>(grupoService, entityManager, Grupo.class, messageUtil);
grupoFiltro = new Grupo();
}
The class that uses it:
public BaseLazyModelJPA(BaseService<T, PK> baseService,
EntityManager entityManager, Class<T> entityClass,
MessageUtil messageUtil) {
this.entityManager = entityManager;
}
Can any body help me figure this out?