Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB 3.0 deployment on TOMEE

 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am very new to EJB technology and trying to develop a simple EJB application. I learnt that TOMEE server has EJB container in it and so trying to deploy the application in it.
However, the container is not injecting my stateless session bean and throws NullPointerException.
Here are the details of what I have done.
1) I have a local interface as:
import javax.ejb.Local;

import entity.AuctionEntity;

/**
* @author pkulka34
*
*/
@Local
public interface AuctionManager {
public void createEntity(AuctionEntity auctionEntity);

}

2. Stateless bean
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;

import entity.AuctionEntity;

/**
* Session Bean implementation class AuctionManager
*/
@Stateless
public class AuctionManagerImpl implements AuctionManager{
@PersistenceContext
EntityManagerFactory entityManagerFactory;
EntityManager entityManager = entityManagerFactory.createEntityManager();


/**
* Default constructor.
*/
public AuctionManagerImpl() {
// TODO Auto-generated constructor stub
entityManagerFactory = Persistence.createEntityManagerFactory("AuctionManagement");
}

public void createEntity(AuctionEntity auctionEntity){
entityManager.persist(auctionEntity);
}

}

3. Servlet Code from where I am trying to invoke EJB method
import java.io.IOException;

import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.AuctionManager;
import entity.Bid;

/**
* @author pkulka34
*
*/
public class AuctionServlet extends HttpServlet {

@EJB
private static AuctionManager auctionManager;
private Bid bid;

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

bid = new Bid();

String bidAmt = null;
String approval = null;
int bitAmount = 0;

// TODO Auto-generated method stub
System.out.println("In Auctionservlet,invoking EJB");

bidAmt = req.getParameter("bidAmt");
/*if(bidAmt!=null){
bitAmount = Integer.parseInt(bidAmt);
}
approval = req.getParameter("approval");*/

bid.setBitAmt(bitAmount);
bid.setApproval(approval);

//bid.createEntity();
auctionManager.createEntity(bid);

}
}

4. I have the bean interface and bean classes in an EJB project. I exported JAR of this project and put in TOMEE's common lib location.
5. Servlet application is also deployed on TOMEE.

Am I missing any configuration steps for TOMEE to work as EJB container? I learnt from some forums that on successful deployment of EJB project on TOMEE, the container creates JNDI entry for the beans which can be referred by clients like servlets etc.
Any help will be very much appreciated since I have been trying to get this work since long

Thanks in advance,
Prajakta
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to the Ranch

Please UseCodeTags when posting code. Click on the link to understand how that is done.
 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posting my query with code tags.

Hi,

I am very new to EJB technology and trying to develop a simple EJB application. I learnt that TOMEE server has EJB container in it and so trying to deploy the application in it.
However, the container is not injecting my stateless session bean and throws NullPointerException.
Here are the details of what I have done.
1) I have a local interface as:


2. Stateless bean


3. Servlet Code from where I am trying to invoke EJB method


4. I have the bean interface and bean classes in an EJB project. I exported JAR of this project and put in TOMEE's common lib location.
5. Servlet application is also deployed on TOMEE.

Am I missing any configuration steps for TOMEE to work as EJB container? I learnt from some forums that on successful deployment of EJB project on TOMEE, the container creates JNDI entry for the beans which can be referred by clients like servlets etc.
Any help will be very much appreciated since I have been trying to get this work since long

Thanks in advance,
Prajakta
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic