我已经为此找到了答案但是却未能找到任何这样的问题来向这个非常适合的社区提出这些问题!
<class>com.mycompany.model.MyEntityBean</class>
。如果我省略了在文件中显式包含实体类,则实体bean - 虽然已注释 - 会引发错误:“Class”com.mycompany.model.MyEntityBean“已映射,但不包含在任何持久性单元中“我有什么假设?谢谢社区!
p.s - 我使用EclipseLink作为JPA供应商而不是它应该重要吗?
以下是我的persistence.xml
的示例<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="Development">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.mycompany.model.MyEntityBean</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.ibm.db2.jcc.DB2Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:db2://xxxxxxx" />
<property name="javax.persistence.jdbc.password" value="xxxxxx" />
<property name="javax.persistence.jdbc.user" value="xxxxxxxx" />
</properties>
</persistence-unit>
<persistence-unit name="QA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.mycompany.model.MyEntityBean</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.ibm.db2.jcc.DB2Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:db2://xxxxxxx" />
<property name="javax.persistence.jdbc.password" value="xxxxxx" />
<property name="javax.persistence.jdbc.user" value="xxxxxxxx" />
</properties>
</persistence-unit>
</persistence>
答案 0 :(得分:4)
“定义了多个持久性单元 - 只有第一个持久性 单位将被认可“是Eclipse(大理)问题。更多关于主题 你可以从bug 231527找到。
因为您有独立的Java SE应用程序,所以实体应该在persistence.xml中列出。在规范中,这个拼写如下:
To insure the portability of a Java SE application, it is necessary to explicitly list the managed persistence classes that are included in the persistence unit using the class element of the persistence.xml file.