I've looked for answers for this but haven't been able to find any so asking these questions to this very apt community!
<class>com.mycompany.model.MyEntityBean</class>
. If I omit the explicit inclusion of the entity class in the file, the entity bean - although annotated - throws an error: "Class "com.mycompany.model.MyEntityBean" is mapped, but is not included in any persistence unit" What I have I assumed wrong?Thank you community!
p.s - I'm using EclipseLink as the JPA vendor not that it should matter??
Here is an example of my 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>
"Multiple persistence units defined - only the first persistence unit will be recognized" is Eclipse (Dali) issue. More about subject you can find from bug 231527.
Because you have standalone Java SE application, entities should be listed in persistence.xml. In specification this is spelled out as follows:
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.
You can turn off the erroneous warning by doing the following. These instructions are for Eclipse Luna.
Project Properties => JPA => Errors/Warnings
Check Enable project specific settings
Expand Project
group
Change Multiple persistence units defined:
to Ignore
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With