This content has been marked as final.
Show 2 replies
-
1. Re: run EntityQuery outside seam context
gjeudy Sep 30, 2008 8:43 PM (in response to mrossix)I think you got your answer. If you try to use a Seam component outside it's context it will not work because dependencies are not injected in the component, transaction is not started etc...
The assumption is that a Seam application context should be active in this case.
-
2. Re: run EntityQuery outside seam context
mrossix Oct 1, 2008 10:59 AM (in response to mrossix)The dependencies can be injected "by hand". If i create my custom dao i can resuse it in other "non seam" project. For example:
@Name("personDAO")
@Scope(ScopeType.CONVERSATION)
public class PersonDAO {
@In EntityManager em;
public List<Person> loadPersons()
{
return em.createQuery("select p from Person p").getResultList();
}
.....
...
}
To use it outside seam:
PersonDAO personDAO = new PersonDAO ();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("helloworld12");
EntityManager em = emf.createEntityManager();
// manual injection
personDAO .setEm(em);
personDAO .loadPersons();
Obviously i loose the seam feature (like conversation in this case), but i can reutilize the same dao, e.g. for a batch precess.
But this approach doesn't work with the daos generated by seam application framework.