Is JPA persistence.xml classpath located?
        Posted  
        
            by Vinnie
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Vinnie
        
        
        
        Published on 2010-04-14T14:59:35Z
        Indexed on 
            2010/04/14
            15:03 UTC
        
        
        Read the original article
        Hit count: 346
        
Here's what I'm trying to do. I'm using JPA persistence in a web application, but I have a set of unit tests that I want to run outside of a container.
I have my primary persistence.xml in the META_INF folder of my main app and it works great in the container (Glassfish).
I placed a second persistence.xml in the META-INF folder of my test-classes directory.  This contains a separate persistence unit that I want to use for test only.  In eclipse, I placed this folder higher in the classpath than the default folder and it seems to work.
Now when I run the maven build directly from the command line and it attempts to run the unit tests, the persistence.xml override is ignored.  I can see the override in the META-INF folder of the maven generated test-classes directory and I expected the maven tests to use this file, but it isn't.  My Spring test configuration overrides, achieved in a similar fashion are working.  
I'm confused at to whether the persistence.xml is located through the classpath.  If it were, my override should work like the spring override since the maven surefire plugin explains "[The test class directory] will be included at the beginning the test classpath".
Did I wrongly anticipate how the persistence.xml file is located?
I could (and have) create a second persistence unit in the production persistence.xml file, but it feels dirty to place test configuration into this production file.  Any other ideas on how to achieve my goal is welcome.
© Stack Overflow or respective owner