Announcement Announcement Module
Collapse
No announcement yet.
Spring - entitymanager / transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?

  • #2
    This is naive for you to say
    But because it is inflexible, I created a class
    s˘ i could create dynamic query.
    . Can you provide your config here. I don't think you've enabled transaction manager in your config.

    Comment

    Working...
    X