<tfoot id='6uNWB'></tfoot>

    <legend id='6uNWB'><style id='6uNWB'><dir id='6uNWB'><q id='6uNWB'></q></dir></style></legend>

      <small id='6uNWB'></small><noframes id='6uNWB'>

      <i id='6uNWB'><tr id='6uNWB'><dt id='6uNWB'><q id='6uNWB'><span id='6uNWB'><b id='6uNWB'><form id='6uNWB'><ins id='6uNWB'></ins><ul id='6uNWB'></ul><sub id='6uNWB'></sub></form><legend id='6uNWB'></legend><bdo id='6uNWB'><pre id='6uNWB'><center id='6uNWB'></center></pre></bdo></b><th id='6uNWB'></th></span></q></dt></tr></i><div id='6uNWB'><tfoot id='6uNWB'></tfoot><dl id='6uNWB'><fieldset id='6uNWB'></fieldset></dl></div>
        • <bdo id='6uNWB'></bdo><ul id='6uNWB'></ul>

        我需要&lt;class&gt;persistence.xml 中的元素?

        时间:2023-07-26

            <legend id='xuBrW'><style id='xuBrW'><dir id='xuBrW'><q id='xuBrW'></q></dir></style></legend>
              <tbody id='xuBrW'></tbody>
          1. <i id='xuBrW'><tr id='xuBrW'><dt id='xuBrW'><q id='xuBrW'><span id='xuBrW'><b id='xuBrW'><form id='xuBrW'><ins id='xuBrW'></ins><ul id='xuBrW'></ul><sub id='xuBrW'></sub></form><legend id='xuBrW'></legend><bdo id='xuBrW'><pre id='xuBrW'><center id='xuBrW'></center></pre></bdo></b><th id='xuBrW'></th></span></q></dt></tr></i><div id='xuBrW'><tfoot id='xuBrW'></tfoot><dl id='xuBrW'><fieldset id='xuBrW'></fieldset></dl></div>
          2. <tfoot id='xuBrW'></tfoot>

            <small id='xuBrW'></small><noframes id='xuBrW'>

              <bdo id='xuBrW'></bdo><ul id='xuBrW'></ul>

                • 本文介绍了我需要&lt;class&gt;persistence.xml 中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个非常简单的persistance.xml 文件:

                  <?xml version="1.0" encoding="UTF-8"?><持久化版本="1.0"xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"><persistence-unit name="eventtractor" transaction-type="RESOURCE_LOCAL"><class>pl.michalmech.eventtractor.domain.User</class><class>pl.michalmech.eventtractor.domain.Address</class><class>pl.michalmech.eventtractor.domain.City</class><class>pl.michalmech.eventtractor.domain.Country</class><属性>

                  它有效.

                  但是当我删除 <class> 元素时,应用程序看不到实体(所有类都用 @Entity 注释).

                  是否有任何自动机制来扫描 @Entity 类?

                  解决方案

                  persistence.xml 有一个你可以使用的 jar-file.来自Java EE 5 教程:

                  <块引用>

                  <persistence><persistence-unit name=订单管理"><描述>这个单元管理订单和客户.它不依赖于任何供应商特定的功能,并且可以因此可以部署到任何持久性提供程序.</描述><jta-data-source>jdbc/MyOrderDB</jta-data-source><jar-file>MyOrderApp.jar</jar-file><class>com.widgets.Order</class><class>com.widgets.Customer</class></持久化单元></持久性>

                  这个文件定义了一个持久化单元命名为 OrderManagement,它使用JTA 感知数据源 jdbc/MyOrderDB.jar-fileclass 元素指定托管持久性类:实体类、可嵌入类和映射超类.jar-file 元素指定对包含托管持久性类的打包持久性单元可见的 JAR 文件,而 class 元素显式命名托管持久性类.

                  如果是 Hibernate,请查看 第二章.设置和配置了解更多详情.

                  实际上,如果您不介意不符合规范,Hibernate 甚至在 Java SE 中也支持自动检测.为此,请添加 hibernate.archive.autodetection 属性:

                  <persistence-unit name="eventtractor"事务类型=RESOURCE_LOCAL"><!-- 这需要符合规范,但 Hibernate 支持即使在 JSE 中也可以自动检测.<class>pl.michalmech.eventtractor.domain.User</class><class>pl.michalmech.eventtractor.domain.Address</class><class>pl.michalmech.eventtractor.domain.City</class><class>pl.michalmech.eventtractor.domain.Country</class>--><属性><!-- 扫描带注释的类和 Hibernate 映射 XML 文件 --><属性名称=hibernate.archive.autodetection"值=类,hbm"/><属性名称=hibernate.hbm2ddl.auto"值=验证";/><属性名称=hibernate.show_sql";值=真";/></属性></持久化单元>

                  I have very simple persistance.xml file:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <persistence version="1.0"
                      xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
                  
                      <persistence-unit name="eventractor" transaction-type="RESOURCE_LOCAL">
                          <class>pl.michalmech.eventractor.domain.User</class>
                          <class>pl.michalmech.eventractor.domain.Address</class>
                          <class>pl.michalmech.eventractor.domain.City</class>
                          <class>pl.michalmech.eventractor.domain.Country</class>
                  
                          <properties>
                              <property name="hibernate.hbm2ddl.auto" value="validate" />
                              <property name="hibernate.show_sql" value="true" />
                          </properties>
                      </persistence-unit>
                  
                  </persistence>
                  

                  and it works.

                  But when I remove <class> elements application doesn't see entities (all classes are annotated with @Entity).

                  Is there any automatic mechanism to scan for @Entity classes?

                  解决方案

                  The persistence.xml has a jar-file that you can use. From the Java EE 5 tutorial:

                  <persistence>
                      <persistence-unit name="OrderManagement">
                          <description>This unit manages orders and customers.
                              It does not rely on any vendor-specific features and can
                              therefore be deployed to any persistence provider.
                          </description>
                          <jta-data-source>jdbc/MyOrderDB</jta-data-source>
                          <jar-file>MyOrderApp.jar</jar-file>
                          <class>com.widgets.Order</class>
                          <class>com.widgets.Customer</class>
                      </persistence-unit>
                  </persistence>
                  

                  This file defines a persistence unit named OrderManagement, which uses a JTA-aware data source jdbc/MyOrderDB. The jar-file and class elements specify managed persistence classes: entity classes, embeddable classes, and mapped superclasses. The jar-file element specifies JAR files that are visible to the packaged persistence unit that contain managed persistence classes, while the class element explicitly names managed persistence classes.

                  In the case of Hibernate, have a look at the Chapter2. Setup and configuration too for more details.

                  EDIT: Actually, If you don't mind not being spec compliant, Hibernate supports auto-detection even in Java SE. To do so, add the hibernate.archive.autodetection property:

                  <persistence-unit name="eventractor" transaction-type="RESOURCE_LOCAL">
                    <!-- This is required to be spec compliant, Hibernate however supports
                         auto-detection even in JSE.
                    <class>pl.michalmech.eventractor.domain.User</class>
                    <class>pl.michalmech.eventractor.domain.Address</class>
                    <class>pl.michalmech.eventractor.domain.City</class>
                    <class>pl.michalmech.eventractor.domain.Country</class>
                     -->
                  
                    <properties>
                      <!-- Scan for annotated classes and Hibernate mapping XML files -->
                      <property name="hibernate.archive.autodetection" value="class, hbm"/>
                  
                      <property name="hibernate.hbm2ddl.auto" value="validate" />
                      <property name="hibernate.show_sql" value="true" />
                    </properties>
                  </persistence-unit>
                  

                  这篇关于我需要&lt;class&gt;persistence.xml 中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                    <tbody id='hFnuj'></tbody>
                  <legend id='hFnuj'><style id='hFnuj'><dir id='hFnuj'><q id='hFnuj'></q></dir></style></legend>
                    • <bdo id='hFnuj'></bdo><ul id='hFnuj'></ul>

                    • <small id='hFnuj'></small><noframes id='hFnuj'>

                      1. <i id='hFnuj'><tr id='hFnuj'><dt id='hFnuj'><q id='hFnuj'><span id='hFnuj'><b id='hFnuj'><form id='hFnuj'><ins id='hFnuj'></ins><ul id='hFnuj'></ul><sub id='hFnuj'></sub></form><legend id='hFnuj'></legend><bdo id='hFnuj'><pre id='hFnuj'><center id='hFnuj'></center></pre></bdo></b><th id='hFnuj'></th></span></q></dt></tr></i><div id='hFnuj'><tfoot id='hFnuj'></tfoot><dl id='hFnuj'><fieldset id='hFnuj'></fieldset></dl></div>
                        <tfoot id='hFnuj'></tfoot>