开发者

jboss 6.1.0.final gwt and ejb combination

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
publ开发者_运维百科ic 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;
}
}


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜