Hello,

I try to use EJB3 in portlet, but it just raised NullPointerException !
Could you please to teach me how to solve it ?



  | @Stateless
  | @Local(ProductLocal.class)
  | public class ProductBean implements ProductLocal {
  |     @PersistenceContext
  |     // (unitName="cal")
  |     protected EntityManager em;
  | 
  |     /**
  |      * 
  |      */
  |     public ProductBean() {
  |             super();
  |             // TODO Auto-generated constructor stub
  |     }
  | 
  |     /**
  |      * (non-Javadoc)
  |      * 
  |      * @see mo.reales.ejb.session.ProductLocal#addProduct(java.lang.String,
  |      *      java.lang.String, java.lang.String, float, int, int,
  |      *      java.lang.String, java.lang.String)
  |      */
  |     public void addProduct(String buildingName, String floor, String flat,
  |                     float area, int totalRoom, int totalSittingRoom, String 
direction,
  |                     String description) {
  | 
  |             Product product = new Product();
  |             product.setBuildingName(buildingName);
  |             product.setFlat(floor);
  |             product.setFlat(flat);
  |             product.setArea(area);
  |             product.setTotalRoom(totalRoom);
  |             product.setTotalSittingRoom(totalSittingRoom);
  |             product.setDirection(direction);
  |             product.setDescription(description);
  | 
  |             em.persist(product);
  |     }
  | 
  |     /** 
  |      * (non-Javadoc)
  |      * @see mo.reales.ejb.session.ProductLocal#getProducts()
  |      */
  |     public Collection<Product> getProducts() {
  |             return em.createQuery("from Product p").getResultList();
  | 
  |     }
  | }
  | 


  | public interface ProductIF {
  |     /**
  |      * Add new product
  |      * 
  |      * @param buildingName
  |      * @param floor
  |      * @param flat
  |      * @param area
  |      * @param totalRoom
  |      * @param totalSittingRoom
  |      * @param direction
  |      * @param description
  |      */
  |     public void addProduct(String buildingName, String floor, String flat,
  |                     float area, int totalRoom, int totalSittingRoom, String 
direction,
  |                     String description);
  |     
  |     
  |     /**
  |      * get all the products
  |      * 
  |      * @return
  |      */
  |     public Collection<Product> getProducts();
  |     
  | }
  | 
  | 


  | public interface ProductLocal extends ProductIF {
  |     
  |     
  | }
  | 


  | public class ProductDAO implements ProductIF {
  |     
  |     @EJB
  |     protected ProductLocal productLocal;
  | 
  |     /**
  |      * 
  |      */
  |     public ProductDAO() {
  |             super();
  |     }
  | 
  |     /*
  |      * (non-Javadoc)
  |      * 
  |      * @see mo.reales.ejb.session.ProductIF#addProduct(java.lang.String,
  |      *      java.lang.String, java.lang.String, float, int, int,
  |      *      java.lang.String, java.lang.String)
  |      */
  |     public void addProduct(String buildingName, String floor, String flat,
  |                     float area, int totalRoom, int totalSittingRoom, String 
direction,
  |                     String description) {
  |             
  |             productLocal.addProduct(buildingName, floor, flat, area, 
totalRoom,
  |                             totalSittingRoom, direction, description);
  | 
  |     }
  | 
  |     /*
  |      * (non-Javadoc)
  |      * 
  |      * @see mo.reales.ejb.session.ProductIF#getProducts()
  |      */
  |     public Collection<Product> getProducts() {
  |             return productLocal.getProducts();
  |     }       
  | }
  | 

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3926468#3926468

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3926468


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to