aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB 3.0 deployment on TOMEE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3.0 deployment on TOMEE" Watch "EJB 3.0 deployment on TOMEE" New topic
Author

EJB 3.0 deployment on TOMEE

Prajakta Acharya
Ranch Hand

Joined: Nov 08, 2012
Posts: 138

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


Regards,
Prajakta
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1088
    
  10

Hi,
Welcome to the Ranch

Please UseCodeTags when posting code. Click on the link to understand how that is done.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Prajakta Acharya
Ranch Hand

Joined: Nov 08, 2012
Posts: 138

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB 3.0 deployment on TOMEE