简体   繁体   中英

java.lang.illegalstateexception unable to retrieve entitymanagerfactory for unitname null

I write Entity.jar .It's EJB Module contain entity class and etitydao class. When i run it on GlassFish , i have error:

Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138)
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTxRequiredCheck(EntityManagerWrapper.java:158)
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTransactionScopedTxCheck(EntityManagerWrapper.java:151)
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:281)
    at com.styl.thincapayment.dao.impl.DataAccessImpl.insertToDatabase(DataAccessImpl.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)

I think it comes from persistence.xml . I put it wrong place. How to resolve this problem.

  • I put persistence file in entities/src/resources/persistence.xml . I use Maven to manage project

  • Declaration EntityManager:

    @PersistenceContext(unitName="entities")

    protected EntityManager entityManager;

persistence.xml should be put inside the folder CLASS_PATH_ROOT/META-INF .

If you are using Maven 's standard project layout , the path should be src/main/resources/META-INF/persistence.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM