users@glassfish.java.net

Re: Glashfish 3 NetBeans 6.9 _at_EJB reference is null

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 23 Jun 2010 08:44:47 -0700

Hi,

You need to turn the root resource class into a managed bean.

Annotate the class with @ManagedBean, or if using CDI annotate with
@RequestScoped.

It is necessary to opt in for such behavior because being a managed
bean subtly changes the programming model of JAX-RS meaning existing
JAX-RS apps may break if it is assumed they are always managed beans.

Paul.


On Jun 23, 2010, at 7:52 AM, glassfish_at_javadesktop.org wrote:

> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>