Note that there are some explanatory texts on larger screens.

plurals
  1. POEJB EntityManager results in NullPointerException
    primarykey
    data
    text
    <p>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:</p> <pre><code> if (existfeed == null) { feed = loadFeed(url, syndfeed); em.persist(feed); if (feed.getFeedId() == null) { return "Persist of feed failed"; } uf.setFeedId(feed); uf.setUserId(user_id); try { em.persist(uf); 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()); if(dbFeed==null) return "Faile to get feed from database"; //http://appleinsider.ru/feed uf.setFeedId(dbFeed); uf.setUserId(user_id); try { em.persist(uf); } catch (PersistenceException ex) { //System.out.println(ex.getMessage()); return "Unable to persist userfeed"; } return "Feed added, existing"; } </code></pre> <p>However, if user added a feed, another user cannot add it and there is the error:</p> <pre><code> 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 </code></pre> <p>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.</p> <p>UPDATE: I tried to use EntityManager find method, it resulted same error. So, definitely, EntityManager is somehow null in second part of if statement.</p> <p>Thanx for all the help. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload