我写了Entity.jar。它的EJB模块包含实体类和etitydao类。当我在GlassFish上运行它时,我有错误:
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)
我认为它来自persistence.xml。我说错了地方。如何解决此问题。
我将持久性文件放在entities / src / resources / persistence.xml中。我使用Maven来管理项目
声明EntityManager:
@PersistenceContext(的unitName ="实体&#34)
受保护的EntityManager entityManager;
答案 0 :(得分:1)
persistence.xml
应放在文件夹CLASS_PATH_ROOT/META-INF
中。
如果您使用的是Maven的standard project layout,则路径应为src/main/resources/META-INF/persistence.xml