Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3217626
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:25:59+00:00 2026-05-17T15:25:59+00:00

I have two persistence.xml files, for the sake of testing: src/main/resources/META-INF/persistence.xml src/test/resources/META-INF/persistence.xml How to

  • 0

I have two persistence.xml files, for the sake of testing:

  • src/main/resources/META-INF/persistence.xml
  • src/test/resources/META-INF/persistence.xml

How to instruct Maven to ignore the first file during testing? Now it is not ignored since OpenEJB says:

ERROR - FAIL ... Finder: @PersistenceContext unitName has multiple matches: 
unitName "abc" has 2 possible matches.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:26:00+00:00Added an answer on May 17, 2026 at 3:26 pm

    Check out the alternate descriptors functionality which is aimed at what you’re trying to do.

    Try this setup:

    • src/main/resources/META-INF/persistence.xml
    • src/main/resources/META-INF/test.persistence.xml

    Then you can construct OpenEJB to prefer the test.persistence.xml file by setting the openejb.altdd.prefix System or InitialContext property to test

    A different possible solution could be to override the persistence unit properties in the test. With that approach you could avoid the need for a second persistence.xml which can be nice as maintaining two can be a pain.

    You can use the Maven approach, but be aware that per spec the persistence provider will only look (aka scan) for @Entity beans in the exact jar or directory where the persistence.xml is found. So be keenly aware that in Maven these are two different locations:

    • target/classes
    • target/test-classes

    EDIT More details on the overriding capabilities

    You can override any property in your test setup via either system properties or the initial context properties (this includes jndi.properties files). The format is:

    <unit-name>.<property>=<value>
    

    So for example with the following persistence.xml:

    <persistence>
      <persistence-unit name="movie-unit">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>movieDatabase</jta-data-source>
        <non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source>
        <properties>
          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
          <property name="hibernate.max_fetch_depth" value="3"/>
        </properties>
      </persistence-unit>
    </persistence>
    

    You can override and add persistence unit properties in your test case. There are currently no facilities for removing them (if you have a need for that let us know – it hasn’t really come up so far).

    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.openejb.client.LocalInitialContextFactory");
    
    p.put("movie-unit.hibernate.hbm2ddl.auto", "update");
    p.put("movie-unit.hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    
    context = new InitialContext(p);
    

    Or alternatively via a jndi.properties file

    java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory
    movie-unit.hibernate.hbm2ddl.auto = update
    movie-unit.hibernate.dialect = org.hibernate.dialect.HSQLDialect
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my current project structure: pom.xml /src /main /resources hibernate.cfg.xml /META-INF persistence.xml I
I have one persistence unit configured in my persistence.xml but i have two databases.
Have two folders with approx. 150 java property files. In a shell script, how
I have two applications written in Java that communicate with each other using XML
I have two threads, one needs to poll a bunch of separate static resources
I have two persistence objects in my app: Things and tags attached to things.
This is the directory structure of the project (maven2 is used): pom.xml /src /main
I have two pages: index.html and main.html When i set the main.html page to
I have two Eclipse Maven Java projects. A domain project that is laden with
I have two questions regarding how to create / use the JDO persistence manager

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.