问题描述
我有很简单的persistance.xml文件:
<?XML版本=1.0编码=UTF-8&GT?;
<持久性版本=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\"> <持久性单位名称=eventractor交易型=RESOURCE_LOCAL>
<类别和GT; pl.michalmech.eventractor.domain.User< /班>
<类别和GT; pl.michalmech.eventractor.domain.Address< /班>
<类别和GT; pl.michalmech.eventractor.domain.City< /班>
<类别和GT; pl.michalmech.eventractor.domain.Country< /班> <性状>
<属性名=hibernate.hbm2ddl.autoVALUE =验证/>
<属性名=hibernate.show_sqlVALUE =真/>
< /性状>
< /持久化部>< /持久>
和它的作品。
但是,当我删除<类>
元素的应用程序没有看到实体(所有的类都标注了 @Entity
)。
有没有自动机制来扫描 @Entity
类?
persistence.xml中有一个 JAR文件
,您可以使用。从:
This file defines a persistence unitnamed OrderManagement
, which uses aJTA-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;类别和GT; persistence.xml中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!