Why JPA injection not works on @PersistentUnit

Posted by Dewfy on Stack Overflow See other posts from Stack Overflow or by Dewfy
Published on 2010-04-04T09:32:04Z Indexed on 2010/04/04 9:43 UTC
Read the original article Hit count: 281

Hello colleagues! It is continues of question ( http://stackoverflow.com/questions/2570976/struts-2-bean-is-not-created ) I'm using struts2 + toplink in my very simple web application under Tomcat. On the page I would like use iteration tag. That is why I've declared some factory (SomeFactory) that resolves collection of entities (Entity). Per article: http://download-uk.oracle.com/docs/cd/B32110_01/web.1013/b28221/usclient005.htm#CIHCEHHG the only thing I need is declaration:

@PersistenceContext(unitName="name_in_persistence_xml")
public class SomeFactory
{
    @PersistenceUnit(unitName="name_in_persistence_xml")
    EntityManagerFactory emf;

    public EntityManager getEntityManager() {
       assert(emf != null); //HERE every time it is null
       return emf.createEntityManager();
    }
    public Collection<Entity> getAll()
    {
       return getEntityManager().createNamedQuery("Entity.findAll").getResultList();
}
}

What is wrong? May be i miss something in web.xml? How to pre-init toplink for web application to allow injection happen?

© Stack Overflow or respective owner

Related posts about struts

Related posts about toplink