Results 1 to 2 of 2

Thread: Spring - entitymanager / transaction

  1. #1
    Join Date
    Nov 2012
    Posts
    7

    Default 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. #2
    Join Date
    Dec 2009
    Location
    India
    Posts
    108

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •