簡體   English   中英

java.lang.illegalstateexception無法檢索單位名稱為null的entitymanagerfactory

[英]java.lang.illegalstateexception unable to retrieve entitymanagerfactory for unitname null

我寫了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 = “實體”)

    受保護的EntityManager實體管理器;

persistence.xml應該放在文件夾CLASS_PATH_ROOT/META-INF

如果您使用的是Maven的標准項目布局 ,則路徑應為src/main/resources/META-INF/persistence.xml

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM