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 8384865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:31:11+00:00 2026-06-09T17:31:11+00:00

I am trying to test an Stateless bean with JUnit in netbeans. This bean

  • 0

I am trying to test an Stateless bean with JUnit in netbeans. This bean uses an EntityManager.

@Stateless
public class myEjb{
    @PersistenceContext
    private EntityManager em;

    public MyResult getResult(){
        return em.find(...);
    }
}

Then I write a test class.

public class myTest{
    private static EJBContainer ec;
    private static Context ctx;

    @BeforeClass
    public static void setUpClass(){
        ec = EJBContainer.createEJBContainer();
        ctx = ec.getContext();
    }
    ....
}

When I run the test, it does not work. I obtain the following message:
Invalid resource : mydb__pm
The error occurs when this line is executed:

ec = EJBContainer.createEJBContainer();

If a change my bean by removing the entity manager, it works. So, it seems that I have a problem with the entity manager.
My persistence.xml file is simple:

<persistence version="2.0" ...>
  <persistence-unit name="MetisDemoPU" transaction-type="JTA">
    <jta-data-source>MyDb</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>

Finally, I create a JSF managed bean that called my EJB (which uses the entity manager) and it works.

@ManagedBean
@RequestScoped
public class myManagedBean{
    @EJB
    private OfferEjb offerEjb;

    ...
}

Any help would be appreciated!

  • 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-09T17:31:12+00:00Added an answer on June 9, 2026 at 5:31 pm

    Ok, I find a solution to my problem. I am now able to use JUnit to test my session bean with a persistence context.
    I am not a specialist, so my explanation will probably not be complete.
    With netbeans 7.2, there is an embedded glassfish server which is used for the test. It is necessary to configure the jdbc parameters in the domain.xml file and then for me it works.
    On my computer, this file is under

    C:\Program Files\glassfish-3.1.2.2\glassfish\domains\domain\
    

    I just add a jdbc connection pool and a jdvc jndi.

    This article contains more details.

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

Sidebar

Related Questions

This is the class I'm trying to test: @Stateless public class Finder { @PersistenceContext(unitName
I'm trying to test a stateless session bean with an EntityManager dependency. This is
i am trying to test this method: [Test] public void Test_GetReferenceValue() { Person person=
just trying to test for equality in this piece of code, but getting a
I trying to test an AccountController that uses DotNetOpenAuth but I am running into
I'm trying to test my Session Beans with JUnit, but I can't. I've tried
I am trying to test on a private development server, and I can't use
I'm trying to unit test a simple EJBModule project under NetBeans 7.1, but I
I'm trying to create an EJB factory class, which works like this: You have
Im currently trying to test an insert method which uses TryUpdateModel(). I am faking

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.