[jboss-user] [EJB3] - EJB EntityManager results in NullPointerException

Ibragim Gapuraev do-not-reply at jboss.com
Mon Jul 1 14:30:37 EDT 2013

Ibragim Gapuraev [https://community.jboss.org/people/sermilion] created the discussion

"EJB EntityManager results in NullPointerException"

To view the discussion, visit: https://community.jboss.org/message/825825#825825

I have an error that I cannot logically understand. I am implementing RSS processing app. The logic is that user takes link of some RSS feed and adds to database. If the feed already exist in database, it takes the id of feed and adds it to subscriptions of the user. Here is the code:

     if (existfeed == null) {
            feed = loadFeed(url, syndfeed);
            if (feed.getFeedId() == null) {
                return "Persist of feed failed";
                try {
                    loadFeedItems(syndfeed, feed);
                    //boolean ufadded = uf.addUserFeed(em);
                } catch (NoResultException ex) {
                    return "Persist of userfeed failed";
                } catch (PersistenceException ex) {
                    return "Persist of userfeed failed, em";
                //boolean ufadded = uf.addUserFeed(em);

                //return true;                
            return "Feed added";
        } else {
            dbFeed = getFeed(feed.getLink());
                return "Faile to get feed from database";
            try {
            } catch (PersistenceException ex) {
                return "Unable to persist userfeed";
            return "Feed added, existing";

However, if user added a feed, another user cannot add it and there is the error:

      Caused by: java.lang.NullPointerException
at ejb.FeedBean.addNewFeed(FeedBean.java:203) [Group_7_Impl_uwx09sua-ejb.jar:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [classes.jar:1.6.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [classes.jar:1.6.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [classes.jar:1.6.0_51]
at java.lang.reflect.Method.invoke(Method.java:597) [classes.jar:1.6.0_51]
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory

I just dont see why would it fail. One of my opinion is that possibly, EntityManager somehow is null. But, in first part of if statement it works.
I tried to use EntityManager find method, it resulted same error. So, definitely, EntityManager is somehow null in second part of if statement.
Thanx for all the help.

Reply to this message by going to Community

Start a new discussion in EJB3 at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130701/343bdc8d/attachment.html 

More information about the jboss-user mailing list