Skip to content
  • Home
  • Search
  • Tools
  • About
  • Terms of Service Agreement
  • Log In
  • Guest

WILDFLY/JBOSS: WFLYJPA0061: Persistence unitName was not specified and double persistence unit definitions

Posted on May 6, 2020January 21, 2021 By Andre Dias
java

 

Table of Contents

  • >PROBLEM
  • >SOLUTION
  • >WHAT NOT TO DO
      • >WRONG EXAMPLE
      • >CONCLUSIONS FROM THE WRONG EXAMPLE
      • >WHY?
  • >TIP – EXTRA INFORMATION
  • >ENV

>PROBLEM

Creating a persistence.xml file having two persistence units caused the following Wildfly’s error message:

Caused by: java.lang.IllegalArgumentException: WFLYJPA0061: Persistence unitName was not specified and there are 2 persistence unit definitions in application deployment deployment “todos.war”. Either change the application deployment to have only one persistence unit definition or specify the unitName for each reference to a persistence unit.

The persistence.xml configuration used was:

 

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
   xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
        http://xmlns.jcp.org/xml/ns/persistence
        http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
        
    <persistence-unit name="primary">
       <jta-data-source>java:jboss/datasources/TasksJsfQuickstartDS</jta-data-source>
       <properties>
          <!-- Properties for Hibernate -->
          <property name="hibernate.hbm2ddl.auto" value="create-drop" />
          <property name="hibernate.show_sql" value="false" />
       </properties>
    </persistence-unit>

    <persistence-unit name="pgTestoneDS">
       <jta-data-source>java:jboss/datasources/pgTestoneDS</jta-data-source>
       <properties>
<!--           <property name="hibernate.hbm2ddl.auto" value="create-drop" /> -->
<!--           <property name="hibernate.show_sql" value="false" /> -->
       </properties>
    </persistence-unit>

</persistence>

 

>SOLUTION

 

After some failures, I’ve decided to repeat the same configuration but doing things in a different order.
The following order was successful:

1. Refactor the code that concerns the primary persistent-unit (or the initial persistent-unit, whatever the name it has).

2. Create a qualifier for this first persistent-unit.

3. Refactor the DAO layer in order to apply its qualifier where the entity manager is injected.

4. Recompile the project and perform a full deployment.

5. Start the server and test.

6. Stop the server

7. If not successful, fix the code revising from step 1.

8. if successful, add the second persistent-unit to persistence.xml file.

9. Create the database manager class, its qualifier, the entities, and DAO layer always using the respective qualifier for the second persistent-unit to differ from the initial code implemented for the first persistent-unit.

10. Recompile the project and perform a full deployment.

11. Start the server and test.

 

 

 

 

SOURCE CODE

todos_double_units_200506_210948

 

>WHAT NOT TO DO

Do not comment or remove the subsystem JPA policy from standalone.xml file.
I found this solution at some sites, but in this case, was not a good idea.
Check the reasons below.

>WRONG EXAMPLE

Edit $SERVER_INSTALL_DIR\standalone\configuration\standalone.xml file.

Find the following configuration:

 

<subsystem xmlns="urn:jboss:domain:jpa:1.1">
	<jpa default-datasource="" default-extended-persistence-inheritance="DEEP"/>
</subsystem>

Comment the configuration like this (line per line):

 

<!--        <subsystem xmlns="urn:jboss:domain:jpa:1.1">-->
<!--            <jpa default-datasource="" default-extended-persistence-inheritance="DEEP"/>-->
<!--        </subsystem>-->

 

Like this:

 

 

 

>CONCLUSIONS FROM THE WRONG EXAMPLE

When the application starts, it fails to load the entity managers.

 

 

 

>WHY?

Int this subsystem JPA configuration, in the server’s standalone.xml file,  there is the following property:


default-extended-persistence-inheritance

Controls how JPA extended persistence context (XPC) inheritance is performed. ‘DEEP’ shares the extended persistence context at the top bean level. ‘SHALLOW’ the extended persistece context is only shared with the parent bean (never with sibling beans).

from:  wildscribe.github.io/WildFly/11.0/subsystem/jpa/index.html

 

This property is responsible for making available the bean instance, following a criterion.
Check next, what the Wildfly’s documentation tells us about this:

– Extended Persistence Context Inheritance
JPA 2.2 specification section 7.6.3.1
If a stateful session bean instantiates a stateful session bean (executing in the same EJB container instance) which also has such an
extended persistence context with the same synchronization type, the extended persistence context of the first stateful session bean
is inherited by the second stateful session bean and bound to it, and this rule recursively applies independently of whether
transactions are active or not at the point of the creation of the stateful session beans.
If the stateful session beans differ in declared synchronization type, the EJBException is thrown by the container.
If the persistence context has been inherited by any stateful session beans, the container does not close the persistence context
until all such stateful session beans have been removed or otherwise destroyed.

from:  github.com/wildfly/wildfly/blob/master/docs/src/main/asciidoc/_developer-guide/JPA_Reference_Guide.adoc

 

 

>TIP – EXTRA INFORMATION

When commenting, avoid comment format like below — using initial and final comments for all lines:

<!--<subsystem xmlns="urn:jboss:domain:jpa:1.1">
  <jpa default-datasource="" default-extended-persistence-inheritance="DEEP"/>
  </subsystem>-->

 

 

>ENV

Windows 10
Wildfly 18
JEE/CDI/JPA

 

Andre Dias
Andre Dias

Brazilian system analyst graduated by UNESA (University Estácio de Sá – Rio de Janeiro). Geek by heart.

Tags: CDI double database sources jboss jpa multiple persistent-unit qualifier server configuration wildfly

Post navigation

❮ Previous Post: WILDFLY/JBOSS: QUICKSTARTS EXAMPLES: org.wildfly.quickstarts 20.0.0.Beta1-SNAPSHOT ISSUE
Next Post: Windows: Windows Cannot Find a System Image on This Computer ❯

Search

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
angular
bootstrap
browser
computer science
container
data persistence
database
devops
editors
hardware
health
hosting
info
internet
it
java
javascript
network
node.js
play
protocol
security
self-help
selfhelp
server
services
soft
software engeneering
sql
support
Systems
techs
Uncategorized
versioning
web
web design
windows
wordpress

Recent Posts

  • Angular From Scratch Tutorial – Step 9: Modal
  • Angular From Scratch Tutorial – Step 8: Miscellany
  • Angular From Scratch Tutorial – Index
  • angular: Reading JSON files
  • NODE.JS: SEQUELIZE: MVC Project – 4TH STEP

Categories

  • angular (19)
  • bootstrap (6)
  • browser (4)
  • computer science (4)
  • container (1)
  • data persistence (2)
  • database (11)
  • devops (1)
  • editors (1)
  • hardware (4)
  • health (2)
  • hosting (1)
  • info (1)
  • internet (2)
  • it (1)
  • java (13)
  • javascript (32)
  • network (6)
  • node.js (1)
  • play (1)
  • protocol (1)
  • security (4)
  • self-help (1)
  • selfhelp (1)
  • server (2)
  • services (1)
  • soft (1)
  • software engeneering (1)
  • sql (1)
  • support (2)
  • Systems (1)
  • techs (3)
  • Uncategorized (2)
  • versioning (6)
  • web (1)
  • web design (5)
  • windows (3)
  • wordpress (4)

Copyright © 2025 .

Theme: Oceanly by ScriptsTown

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT