【问题标题】:How do I override the schema for a JPA app inside a web fragment from a web app?如何在 Web 应用程序的 Web 片段内覆盖 JPA 应用程序的架构?
【发布时间】:2015-08-27 04:16:12
【问题描述】:

所以我有以下内容:

我正在尝试将架构从默认值覆盖为与 web application 不同的架构

我尝试过以下组合:

  • WEB-INF 中使用orm.xml
  • META-INF 内使用orm.xml
  • WEB-INF 内使用persistence.xml
  • META-INF 内使用persistence.xml
  • persistence.xml<mapping-file>META-INF/orm.xml</mapping-file>
  • persistence.xml<mapping-file>WEB-INF/orm.xml</mapping-file>
  • persistence.xml<persistence-unit name="same">
  • persistence.xml<persistence-unit name="different">

无济于事。我试图避免接触web fragment 和便携(所以没有什么像SessionCustomizer 这样的EclipseLink 特定)

【问题讨论】:

    标签: java jakarta-ee jpa


    【解决方案1】:

    如果你想自定义你的持久化设置,你不应该把persistence.xml放在你的web片段中。相反,仅在您的 Web 应用程序的 persistence.xml 中定义所有设置,并在 persistence.xml 中使用 jar-file 添加对您的片段 jar 的引用。您可以在您的片段中定义一个默认的 orm.xml 文件,该文件可以在 Web 应用程序的 persistence.xml 中重用,但并非必须如此。

    为了指定不同的默认模式,请在额外的 orm.xml 文件中定义它,正如我在here 中描述的那样。请记住,您可以为单个持久性单元使用更多 orm 文件,您只需要以不同的方式命名它们。它们将在应用程序的类路径中搜索,包括您的片段。

    【讨论】:

    • 不,没有用,我试着按照你所说的去做(即使没有orm.xml 文件,只有persistence.xml 文件),我得到Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null
    • 我也尝试添加<jar-file>lib/dox-rest...jar</jar-file>,但也没有成功。
    • 您在某处为名为 null 的单元请求 EM。当我有时间看你的视频时,我会调查它
    • 谢谢,我不要求任何名为 null 的东西,但我依赖于 @PersistenceUnit 给出的默认值,没有注释参数
    • 我的回答有误,我有时会忘记这一点:persistence.xml 总是进入 META-INF 文件夹,而不是进入 WEB-INF。尝试从片段中删除persistence.xml 并将其移动到 webapp 中的 META-INF 文件夹。
    猜你喜欢
    • 1970-01-01
    • 2010-12-23
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 2011-09-08
    • 1970-01-01
    • 2015-01-04
    相关资源
    最近更新 更多