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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:02:24+00:00 2026-05-15T11:02:24+00:00

I work on an application which use Seam and Hibernate (with Jboss 5.1 server).

  • 0

I work on an application which use Seam and Hibernate (with Jboss 5.1 server).

I have 4 projects in my eclipse (Portail, Portail-ear, Portail-ejb and Portail-test).
When I start the application, all work fine (I can go in localhost:8080).

But when I want to realise some tests in the test project, I have a problem. Here is the code for the user creation test:

public class UserTest extends SeamTest {  

 @PersistenceContext
 IdentityManager identityManager;

 @PersistenceContext
 private EntityManager entityManager;

 @Test  
 public void testUserCreate() throws Exception {  
         new ComponentTest() {  
             @Override  
             protected void testComponents() throws Exception {

  Log log = Logging.getLog(UserTest.class);
  Log testLog = Logging.getLog(Log.class);

                (UserAction)Component.getInstance("userAction", true);
  setField(ua, "entityManager", entityManager);
  setField(ua, "identityManager", identityManager);
  setField(ua, "log", testLog);
  ua.setCreation(true);
  ua.setConfirm("toto");
  Portailrole portailrole = null;
  try{
      log.info("/****** CHERCHE ROLE ******/");
      if (entityManager == null)
      log.info("entityManager is null");
      Query query = entityManager.createQuery("from Portailrole where name=:rolename").setParameter("rolename", "Admin");
                    portailrole = (Portailrole) query.getSingleResult();
      log.info("/****** FIN CHERCHE ROLE ******/");
  } 
  catch (Exception e) {
           log.info("Exception portailrole {0} {1}", e.getClass(), e.getMessage());
  }
  log.info("testUserCreate : {0}", "role trouvé?");
  Set<Portailrole> portailroles = new HashSet<Portailrole>();
  if (portailrole != null) { 
   log.info("testUserCreate : {0}", portailrole.getName());
   portailroles.add(portailrole);
  }

  Portailuser testUser = new Portailuser(new Long(99999999),"nom","prenom","0123455689","0123455689", "0123455689","toto@toto.fr","login", "toto","FFEFAA", true, portailroles);
  log.info("testUserCreate : {0}", "user créé");
  ua.setUser(testUser);
  if ("failure".equals(ua.save())) {
            log.info("testUserCreate : {0}", "echec du save");
   assert false;
  }
  log.info("testUserCreate : {0}", "user sauvé");
         }.run();  
     }   

And my entityManager is null. I think the @PersistenceContext annotation doens’t work in my case but I don’t understand why.

My hibernate configuration is in the EJB project in META-INF/persistence.xml

Someone has an idea to help me ?

Thanks.

  • 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-15T11:02:24+00:00Added an answer on May 15, 2026 at 11:02 am

    Retrieve the EntityManager inside the ComponentTest.testComponents() method using Component.getInstance() instead of trying to inject it:

    EntityManager em = (EntityManager) Component.getInstance("entityManager");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small application which doesn't seem to work. Please help. Server: var
We have a Server/Client cybercafe management application which used to work fine on Windows
I have a java application which use morphia to work with mongodb. I want
I build an application which use Hibernate JPA2 + Spring. I have problem with
I use JDK 1.6 and I work on an a existing application which is
I have an application which really should be installed, but does work fine when
I have a card-game application which makes use of Single Table Inheritance. I have
I have written a small application which will be used in my work environment
I have a 32bit Delphi application which needs to use Redemption to talk with
I have a spring mvc application which make massive use of beans which are

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.