I have several jar files (tasks.jar, calendar.jar, user.jar, authentication.jar) which I have developed which contains persistence.xml file inside each and every one of them. All these persistence.xml files have the same persistence unit name, say for example 'TASK_MANAGER'.
My question is can I add these jar files in to the JSF web project's lib folder and use them via a managed session bean, which again uses JPA entity manager, with the persistence unit name 'TASK_MANAGER'. Ex:
//All the imports go here (import com.app.model.task) etc....
@ManagedBean
@RequestScoped
public class TaskController{
//Access the entity manager and work with their methods here
}
I know that by http://docs.oracle.com/javaee/6/tutorial/doc/bnbqw.html
If you package the persistence unit in a JAR file that will be included in a WAR or EAR file, the JAR file should be located in either
- The WEB-INF/lib directory of a WAR
- The EAR file’s library directory
But my question is can I do that with multiple persistence.xml files.
Because in Eclipse when I try to achieve this, only the final jar file's persistence file is loaded, I know this because other entities are not recognised when I try to run the application.
How can I include multiple persistence.xml files into one project.
I checked these already Configure persistence units to be available in several jars of an ear and https://stackoverflow.com/questions/23398636/combining-entities-across-jars-in-a-single-persistence-xml-file.
The solution was very simple. The eclipselink wants to know what the sub projects' persistence.xml files are. So in those mini projects which developed JARs, I had to add the following property into their persistence.xml files.
<property name="eclipselink.composite-unit.member" value="true"/>
After that in the main persistence.xml file you have to set the follwing property as well.
<property name="eclipselink.composite-unit" value="true"/>
Now everything works perfectly..