I'm working now with a JPA 2.0 project (in Eclipse Indigo). In my persistence.xml file I need to specify two <persistence-unit> tags, because I have two different database to work with. Doing this, I get the following warning:
Multiple persistence units defined - only the first persistence unit will be recognized
Even more, if I create my entities and put it in my second <persistence-unit>, I get an error saying that my entity isn't declared in a persistence-unit:
Class "my.package.MyClass" is mapped, but is not included in any persistence unit
So, the question is: is possible to declare (and use them as expected) many <persistence-unit> tags in persistence.xml file? If yes, what do I need to do for getting the accurate behavior?
Thanks!
The Java Persistence API allows you to define multiple persistence units, each of which can map to a separate database.
A persistence unit defines a set of all entity classes that are managed by EntityManager instances in an application. This set of entity classes represents the data contained within a single data store.
xml should be put in the EJB JAR's META-INF directory. If you package the persistence unit as a set of classes in a WAR file, persistence. xml should be located in the WAR file's WEB-INF/classes/META-INF directory.
JPA does not limit number of persistence units defined in persistence.xml. This warning just tells about limitation of tool in Eclipse IDE. This is told for example here http://www.eclipse.org/webtools/dali/gettingstarted.php :
Currently Dali only supports one Persistence Unit and one Persistence XML file per project. Other configurations can exist in a JPA project, but the validation and defaults processing may not be correct when multiple persistence units are used.
I guess there is no known way to get this work in Eclipse IDE.
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