users@glassfish.java.net

Glashfish 3 NetBeans 6.9 _at_EJB reference is null

From: <glassfish_at_javadesktop.org>
Date: Wed, 23 Jun 2010 07:52:21 PDT

I am getting a null pointer exception when trying to use a stateless session bean deployed in the ejb.jar from a class in the war.war all packaged in a .ear


-- Deployed in the ejb.jar

@Remote
public interface MarketEntity
{
        public TrendType getTrend(String inExchangeAbbr, String inSymbol);
}

@Stateless
public class MarketEntitySB implements MarketEntity
{
        @Override
        public TrendType getTrend(String inExchangeAbbr, String inSymbol)
        {
                Query theQuery = entityManager.createNamedQuery("MarketEntityPB.selectBySymbol");
                theQuery.setParameter("symbol", inSymbol);
                MarketEntityPB theMarketEntity = (MarketEntityPB) theQuery.getSingleResult();

                theQuery = entityManager.createNamedQuery("MarketEntityDayPointPB.selectPointByMarketEntityRSNOrderByDescendingDate");
                theQuery.setParameter("marketEntityRSN", theMarketEntity.getRSN());
                theQuery.setMaxResults(4);
                List<Point> thePointList = theQuery.getResultList();
                Collections.reverse(thePointList);

                TreeMap<Calendar, OHLCQuote> theQuoteMap = new TreeMap<Calendar, OHLCQuote>();
                theQuery = entityManager.createNamedQuery("MarketEntityDayQuotePB.selectQuoteByMarketEntityRSNStartDateEndDate");
                theQuery.setParameter("marketEntityRSN", theMarketEntity.getRSN());
                theQuery.setParameter("startDate", thePointList.get(0).getDate());
                theQuery.setParameter("endDate", Calendar.getInstance());
                List<OHLCQuote> theQuoteList = theQuery.getResultList();
                for (OHLCQuote theQuote : theQuoteList)
                {
                        theQuoteMap.put(theQuote.getDate(), theQuote);
                }

                List<Trend> theTrendList = TrendCalculator.getTrendList(thePointList, theQuoteMap);
                Trend theTrend = theTrendList.get(theTrendList.size() - 1);
                
                return (theTrend.getType());
        }

        @PersistenceContext
        protected EntityManager entityManager;

        @Resource
        protected SessionContext sessionContext;

        private static final Logger logger = Logger.getLogger(MarketEntitySB.class.getName());
}


-- Deployed in the war.war

@Path("marketentity/{symbol}")
public class MarketEntityResource
{
        /** Creates a new instance of MarketEntityResource */
        public MarketEntityResource()
        {
        }

        /**
         * Retrieves representation of an instance of com.skyviewsoftware.stockmarket.ws.MarketEntityResource
         * @return an instance of java.lang.String
         */
        @GET
        @Produces("application/json")
        public String get(@PathParam("symbol") String inSymbol)
        {
                TrendType theType = marketEntity.getTrend(null, inSymbol);
                
                return ("Trend: " + theType);
        }

        /**
         * PUT method for updating or creating an instance of MarketEntityResource
         * @param content representation for the resource
         * @return an HTTP response with content of the updated or created resource.
         */
        @PUT
        @Consumes("application/json")
        public void put(String inContent)
        {
        }

        @Context
        private UriInfo context;

        @EJB
        private MarketEntity marketEntity;
}


@EJB
private MarketEntity marketEntity;
is not getting injected I am getting a null pointer when trying to use it above. Any ideas of what I have done wrong?
[Message sent by forum member 'glenmiller']

http://forums.java.net/jive/thread.jspa?messageID=475530