Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 353121

Summary: PersistenceUnitLoadingException exception thrown when using EclipseLink inside Tomcat 7 launched from Eclipse with "Serve modules without publishing" enabled
Product: z_Archived Reporter: DenisGL <denis.galiana>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: martin.grebac, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: tomcat

Description DenisGL CLA 2011-07-26 10:43:15 EDT
Build Identifier: 2.3.0.v20110604-r9504

I've tried to make work Tomcat 7 + JSF (myFaces 2) and EclipseLink with Eclipse Helios (tomcat configured and run from Eclipse also) and JDK 1.6, but I have the following problem :
 - the first time i try to create an EntityManagerFactory :
 
emf = Persistence.createEntityManagerFactory("Bank", properties);
 
I get an exception.
 I do this call in a session managed bean call from a web page. If I refresh the page, the call succeeds !

Exception is :

Internal Exception: Exception [EclipseLink-30009] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while trying to load persistence unit at url: file:/C:/WORK/DEV/Bank/EclipseWKS/Bank/WebContent/WEB-INF/classes/
Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while processing persistence.xml from URL: file:/C:/WORK/DEV/Bank/EclipseWKS/Bank/WebContent/WEB-INF/classes/
Internal Exception: java.net.MalformedURLException

(see forum message #693092 in the Eclipse Forum for details).


It seems that it searched for the META-INF/persistence.xml in the WEB-INF/classes directory, which does not exists on my installation.
 If I create the 'classes' directory, i get another exception :
 
Internal Exception: java.io.FileNotFoundException: C:\WORK\DEV\Bank\EclipseWKS\Bank\WebContent\WEB-INF\classes
 

If I copy the META-INF/persistence.xml to this directory, the error disappears.
 
After looking at source code of JPA, it seems that two directories are searched for the persistence.xml file, but on first "not found" an exception is raised, and the second path is not searched.
 
I succeeded to get a workaround of this issue by making a little modification of the source code de EclipseLink :
 
in the PersistenceUnitProcessor class, I have added a try/catch FileNotFoundException, like this :

public static Set<Archive> findPersistenceArchives(ClassLoader loader, String descriptorPath){
        Archive archive = null;

        Set<Archive> archives = new HashSet<Archive>();

        // See if we are talking about an embedded descriptor
        int splitPosition = descriptorPath.indexOf("!/");

        try {
            // If not embedded descriptor then just use the regular descriptor path
            if (splitPosition == -1) {
                Enumeration<URL> resources = loader.getResources(descriptorPath);
                while (resources.hasMoreElements()){

                    URL descUrl = resources.nextElement();
                    URL puRootUrl = computePURootURL(descUrl, descriptorPath);
                    
                    // *** Here is the "patch"
                    try {
                    	archive = PersistenceUnitProcessor.getArchiveFactory(loader).createArchive(puRootUrl, descriptorPath, null);
                    catch (FileNotFoundException ex)
	            {                        // Ignore this path
	              	archive = null;
	            }
	            // End of patch


The same code is also used in the next function, maybe the same patch should be applied.


Reproducible: Always

Steps to Reproduce:
1.Create a Web Project for Tomcat 7 + JPA in Eclipse
2.Configure Tomcat with "Service Modules without publishing"
3.In your program, add the creation of an entity mananger factory in an application managed bean :
emf = Persistence.createEntityManagerFactory("JPUName", properties);
4.Start Tomcat
5.Connect to your web application, so that the managed bean gets executed.
6.The exception is thrown
Comment 1 Eric Gwin CLA 2011-09-13 12:46:31 EDT
This sounds like a JPA code bug. reassigning.
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:33:17 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink