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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:13:55+00:00 2026-05-25T19:13:55+00:00

this is my first post, so if it isn’t understandable, please feel free to

  • 0

this is my first post, so if it isn’t understandable, please feel free to ask.

I’m trying to develop a gwt-application that uses my own ejb-classes from an external shop-project.

My ServiceImpl reaches the ejb, as required, however I’m not able to use Injection as it seems to me. In my ejb-class I call a function to create my test-database with dummy-data. For this (and later on for any requests of course) I wanted to inject an EntityManager. This is done in my Base-Class HomeBase.
the problem: The entityManager may not be initialized. I tryed both annotations:

@PersistenceUnit(unitName = "sung.app.kylintv.ejb")
protected EntityManagerFactory entityManagerFactory;

protected EntityManager entityManager = entityManagerFactory.createEntityManager();

as well, as:

@PersistenceContext(unitName="sung.app.kylintv.ejb")
protected EntityManager entityManager;

I’m running jBoss 6.1.0.Final, GWT 2.4 serverside calling my ejb-function.
JBoss starts up correctly, not showing any errors. However, when calling the function I get this error-message:

Caused by: javax.ejb.EJBException: java.lang.NullPointerException
...
Caused by: java.lang.NullPointerException
at sung.app.kylintv.HomeBase.<init>(HomeBase.java:28) [:]
at sung.app.kylintv.product.ProductHome.<init>(ProductHome.java:35) [:]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [:1.6.0_25]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [:1.6.0_25]
at 

By debugging the function I found the entityManager to be NULL.
How can I get the injection working? Or am I taking a totally wrong approach on this?

For more informations if required:
Code:

package sung.app.kylintv.gwt.server;

import javax.ejb.EJB;

import sung.app.kylintv.gwt.client.DatabaseBuilderService;
import sung.app.kylintv.product.Product;
import sung.app.kylintv.product.ProductHome;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class DatabaseBuilderServiceImpl extends RemoteServiceServlet implements DatabaseBuilderService
{
@EJB(mappedName = "sung/app/kylintv/product" )
private transient Product product;


@Override
public boolean createDefaultDatabaseEntries()
{
    return product.createTestEntry();
}
}

The initiated class (through interface product) ProductHome:

@Stateless(name="Product")
@Local(Product.class)
public class ProductHome extends HomeBase<ProductEntity> implements Serializable, Product
{
@EJB
protected Option sessionOption;

@TransactionAttribute(REQUIRED)
public boolean createTestEntry()
{
    try
    {
        System.out.println("TEST creating Data BEGIN");

        ProductEntity currentProduct = new ProductEntity();

// ++++ fill FIRST product ++++
        currentProduct.setName("bo_product_europe_basic_name");
        currentProduct.setDescription("bo_product_europe_basic_description");

        getEntityManager().persist(currentProduct); **<- HERE THE ERROR OCCURS**

        ... **For better overview I removed the further object-creation**
    }
    catch(Exception e)
    {
        //print out an error message and return false
        System.out.println( e.getCause().getMessage() );
        return false;
    }
    return true;
}

}

The extended HomeBase:

public abstract class HomeBase<T>
{
@PersistenceUnit(unitName = "sung.app.kylintv.ejb")
protected EntityManagerFactory entityManagerFactory;

private EntityManager entityManager = entityManagerFactory.createEntityManager();


//    @PersistenceContext(unitName = "sung_app_kylintv")
//    protected EntityManager entityManager;
//    
public void setEntityManager(EntityManager entityManager) {
    this.entityManager = entityManager;
}


public EntityManager getEntityManager() {
    return entityManager;
}
}
  • 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-25T19:13:56+00:00Added an answer on May 25, 2026 at 7:13 pm

    It looks like you’re trying to set an EntityManager from entityManagerFactory, which I don’t see initialized anywhere. Perhaps you should check to see if protected EntityManagerFactory entityManagerFactory is null. If so, there’s your issue.

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

Sidebar

Related Questions

This is my first post on Stack, so please bear with me if I
First I know that this probably sounds like it isn't the best way to
This is my first post here and I wanted to get some input from
This is my first post and I'm quite a novice on C++ and compiling
This is my first post on Stack Overflow and I'm just wondering on the
This is my first post here. I have a problem. I need to take
this is my first post here on stackoverflow and am very impressed by the
this is my first post on this website, but I'm all the time getting
Well, this is my first post here and really enjoying the site. I have
My first post here, so i hope this is the right area. I am

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.