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

  • Home
  • SEARCH
  • 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 8859837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:08:59+00:00 2026-06-14T15:08:59+00:00

I want to enable Unit Test for my project. I have created the structure

  • 0

I want to enable Unit Test for my project. I have created the structure as follows.

Directory Structure

.
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   └── resources
│   │       ├── META-INF
│   │       │   ├── beans.xml        <-- Works fine in live
│   │       │   └── persistence.xml  <-- Works fine in live
│   └── test
│       ├── java
│       │   ├── com
│       │   │   └── test
│       │   │       └── model
│       │   │           ├── TestEntityManagerUtil.java
│       │   │           └── TestHibernate.java
│       └── resources
│           ├── META-INF
│           │   ├── beans.xml
│           │   └── persistence.xml

CODE

persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="test" transaction-type="RESOURCE_LOCAL">

        <description>TEST Persistence Unit</description>
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <properties>

            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
            <property name="hibernate.connection.url" value="jdbc:mysql://XXX:3306/X" />
            <property name="hibernate.connection.username" value="X" />
            <property name="hibernate.connection.password" value="X" />

            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.transaction.flush_before_completion" value="true" />
        </properties>
    </persistence-unit>
</persistence>

TestEntityManagerUtil.java

public class TestEntityManagerUtil {
    public static EntityManagerFactory getEntityManagerFactory(){
        return Persistence.createEntityManagerFactory("test");
    }
}

TestHibernate.java

public class TestHibernate {

    private EntityManager em;

    @Before
    public void beforeEach(){
        // Exception occurs here
        em = TestEntityManagerUtil.getEntityManagerFactory().createEntityManager();
    }

    @After
    ....

    @Test
    ....
}

Exception

javax.persistence.PersistenceException: No Persistence provider for EntityManager named test
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
    at com.wellclub.model.TestEntityManagerUtil.getEntityManagerFactory(TestEntityManagerUtil.java:12)
    at com.wellclub.model.TestHibernate.beforeEach(TestHibernate.java:24)

The test persistence.xml is exploded in target/test-clases directory as it is.

Can anyone help me what i would be doing wrong.

  • 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-06-14T15:08:59+00:00Added an answer on June 14, 2026 at 3:08 pm

    Please review your JPA implementation library (Hibernate) dependencies in your Maven POM.

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>${hibernate-core-version}</version>
    </dependency>'
    

    Otherwise add hibernate-entityManager.jar in a non Maven project

    Edit:

    Be aware that the JBoss example you are using is an EE application which uses CDI injection to obtain an EntityManager. A major misconception is to assume that a JUnit tests are operational in EE applications…. No, JUnit tests can neither run the JBoss container nor deploy your project. Yet you can refer to http://arquillian.org/invasion/ and also notice the JBoss example for an arquillian test

    In other words, your JUnit is the SE way of testing an EntityManager and it in not operational in an application server like JBoss.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have project in which I want to use check library for unit testing.
I want to enable code coverage for some unit test in my solution. After
I wrote some test and i want to generate unit testing with PHPUnit 3.6
I want to test integration of dao-layer with my service-layer in a unit-test. So
In a Unit Test (in Visual Studio 2008) I want to compare the content
i have a small form. I want enable submit button when all the all
I want to enable data cache. I dont have much experience with ARM as
We want to enable direct streaming of our payload in webservice endpoints. We have
I want to use Boost test in my project. I use cmake in my
I have EditorGridPanel and I want Enable-disable cell values depending on other column value

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.