1 Reply Latest reply on Feb 27, 2006 5:58 AM by Alexander Hartner

    NullPointer Exception !!!

    Eric Chow Apprentice

      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();
       }
      }