EntityManager is not null then what can be the problem?findAll not working

Hello,
I am just a beginner trying to learn JPA. I successfully added record to database but when i tried to display it it throws me null pointer exception. This is the code
index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:form>
            <h:outputLabel value="Username :"/>
            <h:inputText value="#{IndexManagedBean.userName}"/> <br />
            <h:outputLabel value="Password :"/>
            <h:inputText value="#{IndexManagedBean.password}"/> <br />
            <h:outputLabel value="Birthdate :"/>
            <h:inputText value="#{IndexManagedBean.birthdate}">
                <f:convertDateTime dateStyle="medium" type="date"/>
            </h:inputText> <br />
            <h:commandButton value="Add User" actionListener="#{IndexManagedBean.addUser}"/>
            <br />
            <br/>
        </h:form>
    </h:body>
</html>Users.java My Entity bean
* To change this template, choose Tools | Templates
* and open the template in the editor.
package BusinessFacade;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name = "tblusers", catalog = "ssms", schema = "")
@NamedQueries({
    @NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
    @NamedQuery(name = "Users.findByUserId", query = "SELECT u FROM Users u WHERE u.userId = :userId"),
    @NamedQuery(name = "Users.findByUserName", query = "SELECT u FROM Users u WHERE u.userName = :userName"),
    @NamedQuery(name = "Users.findByPassword", query = "SELECT u FROM Users u WHERE u.password = :password"),
    @NamedQuery(name = "Users.findByLastLoginDateTime", query = "SELECT u FROM Users u WHERE u.lastLoginDateTime = :lastLoginDateTime"),
    @NamedQuery(name = "Users.findByBirthdate", query = "SELECT u FROM Users u WHERE u.birthdate = :birthdate")})
public class Users implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "UserId", nullable = false)
    private Integer userId;
    @Basic(optional = false)
    @Column(name = "UserName", nullable = false, length = 50)
    private String userName;
    @Basic(optional = false)
    @Column(name = "Password", nullable = false, length = 50)
    private String password;
    @Basic(optional = false)
    @Column(name = "LastLoginDateTime", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastLoginDateTime;
    @Column(name = "Birthdate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date birthdate;
    public Users() {
    public Users(Integer userId) {
        this.userId = userId;
    public Users(String userName, String password, Date birthDate) {
        this.userName = userName;
        this.password = password;
        this.lastLoginDateTime = new Date();
        this.birthdate = birthDate;
    public Integer getUserId() {
        return userId;
    public void setUserId(Integer userId) {
        this.userId = userId;
    public String getUserName() {
        return userName;
    public void setUserName(String userName) {
        this.userName = userName;
    public String getPassword() {
        return password;
    public void setPassword(String password) {
        this.password = password;
    public Date getLastLoginDateTime() {
        return lastLoginDateTime;
    public void setLastLoginDateTime(Date lastLoginDateTime) {
        this.lastLoginDateTime = lastLoginDateTime;
    public Date getBirthdate() {
        return birthdate;
    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userId != null ? userId.hashCode() : 0);
        return hash;
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        Users other = (Users) object;
        if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
            return false;
        return true;
    @Override
    public String toString() {
        return "BusinessFacade.Users[userId=" + userId + "]";
}UsersFacade.java my Stateless session bean
package BusinessFacade;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
@Stateless
public class UsersFacade {
    @PersistenceContext(unitName = "FirstJpaExamplePU")
    private EntityManager em;
    public void create(Users users) {
        em.persist(users);
    public void edit(Users users) {
        em.merge(users);
    public void remove(Users users) {
        em.remove(em.merge(users));
    public Users find(Object id) {
        return em.find(Users.class, id);
    public List<Users> findAll() {
        return em.createNamedQuery("Users.findAll").getResultList();
    public List<Users> findRange(int[] range) {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Users.class));
        Query q = em.createQuery(cq);
        q.setMaxResults(range[1] - range[0]);
        q.setFirstResult(range[0]);
        return q.getResultList();
    public int count() {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<Users> rt = cq.from(Users.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
}If entitymanager is null then even create should not work, but here findall is not working, create is working perfect!

oops, sorry about that!
here is stack trace :
com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: IndexManagedBean.
     at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:193)
     at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:102)
     at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:405)
     at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:267)
     at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
     at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
     at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
     at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:99)
     at com.sun.el.parser.AstValue.getValue(AstValue.java:158)
     at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
     at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
     at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
     at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
     at javax.faces.component.UIOutput.getValue(UIOutput.java:168)
     at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
     at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:338)
     at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
     at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620)
     at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
     at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
     at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
     at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
     at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
     at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
     at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
     at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
     at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
     at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
     at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233)
     at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
     at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
     at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
     at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
     at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
     at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
     at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
     at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
     at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
     at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
     at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
     at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
     at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
     at BusinessFacade.UsersFacade.findAll(UsersFacade.java:47)
     at IndexManagedBean.<init>(IndexManagedBean.java:23)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
     at java.lang.Class.newInstance0(Class.java:355)
     at java.lang.Class.newInstance(Class.java:308)
     at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188)
     ... 53 moreEventually, i found out the EntityManager is null! But how can it be null. I created a persistence context and gave it proper name in code. Then how it be null?

Similar Messages

  • My ipad will only charge on my mac bookair but not on my sony vaio? what can be the problem?

    anyone please??  i hav an ipad 2 and it dosent charge when i plug it into the wall outlet or my sony vaio laptop, what can be the problem?????????????? when i plug it in it saids not chrging by the battery bar, but once i plug it in to my mac book air it charges normally???? please help

    The iPad should have come with a 10w charger...it is the same charger as used with the iPad 2.  The charger and iPads are interchangable.  If the two of you can share the parts, you take the MacBook and husband the charger you should be able to manage the charging.
    If you have lost or misplaced the chargers, then it would be best to buy another to avoid conflicts, afterall, it is Valentine's Day and best to avoid conflicts

  • I cannot open itunes store from my iphone 4s. When I press the application icon it seems to be open at first but then automatically return to the main menu. What can be the problem?

    I cannot open itunes store from my iphone 4s. When I press the application icon it seems to be open at first but then automatically return to the main menu. What can be the problem?

    Logout of the app store and iTunes store: Settings>iTunes & App Store>Apple ID. Go back to home screen and  reset the phone by pressing the sleep/wake and home buttons together until the Apple logo appears then release them.
    Once phone has finished rebooting go back to  Settings>iTunes & App Store and login with your Apple ID and password again. Then open the iTunes Store app again.

  • HT201407 How come when I try and restore my iPhone 4 GSM (factory unlocked) with itunes, it starts ok, and then at 60% blocks like for about 5 min, and then continues till 100% and itunes give error msg (-1) ??? what can be the problem

    How come when I try to restore my iPhone 4 GSM (factory unlocked) with itunes, it starts ok, then at 60% blocks like for about 5 min, then continues till 100% and itunes give error msg (-1) ??? what can be the problem.
    thank you in advance.

    Error 1 or -1
    This may indicate a hardware issue with your device. Follow Troubleshooting security software issues, and restore your device on a different known-good computer. If the errors persist on another computer, the device may need service.
    http://support.apple.com/kb/TS3694

  • Spotlight and finder cannot find files as of a certain date. What can be the problem and how to solve?

    Spotlight and search field in Outlook on MacBoon cannot find files as of a certain date. What can be the problem and how to solve?

    Reinstall on both.
    Reinstall Lion, Mountain Lion, or Mavericks without erasing drive
    Boot to the Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    Repair
    When the recovery menu appears select Disk Utility. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported then click on the Repair Permissions button. When the process is completed, then quit DU and return to the main menu.
    Reinstall Mountain Lion or Mavericks
    OS X Mavericks- Reinstall OS X
    OS X Mountain Lion- Reinstall OS X
    OS X Lion- Reinstall Mac OS X
         Note: You will need an active Internet connection. I suggest using Ethernet
                     if possible because it isthree times faster than wireless.
    Restore your iPhone to reinstall iOS. Be sure to do this while connected to your computer and iTunes.
         Tap Settings > General > Reset > Erase all content and settings.

  • Photoshop elements 12.1: closes down right after opening the program, what can be the problem?

    Hi!
    I have just purchased Photoshop elements 12, and updated it to 12.1.
    Installation and updating went well, but now the program closes down right after opening it.
    What can be the problem?
    Thanks!

    Hi kalle-veikka,
    If an organizer is not launching then try the steps mentioned in the given link :- https://forums.adobe.com/thread/1475087
    If the issue is with editor then share the log file, locate the log path from given link :- http://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&uact=8&ved=0CDcQF jAC&url=http%3A%2F%2Fhelpx.ado…
    Sarika

  • TS4002 Automatic backup failed.....there is no back up store capacity, but i have enough 5.0 gb.....what can be the problem ?

    Automatic backup failed
    I have enough capacity but its constantly give me this failure
    I cannot safe photo when i see them on a site
    What can be the problem ?

    You say you have enough capacity (on icloud), but it could be that the device's memory is near full (for a backup, the device needs a certain amount of free memory for working files). 
    Go to
    Settings>General>Usage.  This tells how much storage is used on both iCloud and on the device.
    As for photos - do not use icloud as a storage location for them.  First of all, only photos in the camera roll are backed up.  Even then, many user have reported that when they have performed a restore of an icloud backup, the photos were not synced and ended up being gone.
    IMPORTANT...
    Photos should be regularly synced to a computer (like you store photos from a digital camera) using either USB via iTunes (on a mac use iPhoto or Aperture to move them to an album) or using photo stream.  If you have been doing that, then you can sync those photos back to your device if ever they get erased on the device.
    If you haven't been saving photos except relying on iCloud to store them in a backup, then that is risky, as many users have discovered.
    Now - about backups failing...
    If you get the error "Backup not successful" and you've tried deleting the last backup and trying to back up manually without luck, try the following test:   Go to...
    Settings>iCloud>Storage & Backup>manage Storage, tap your device name in the Backups section, then look under Backup options.  Turn off all apps from backup and then do a manual backup.  If that doesn't work, then this post will not help.  If the backup works, then go back to the app list and turn some on and try another backup.  If successful, keep repeating these steps.  If it fails at some point, then try to zero in on the one app that seems to make the backup fail.  (I had this problem and found one app failing, probably due to a corrupt data file.)
    This process will take time, but if a backup works with no app data being used but clearly fails with the original settings, then somewhere in the mix of apps is a "bad" one.

  • Pse trial v12 installed but when opening the editor it shuts down after 2 seconds, what can be the problem? I have windows 8.1 64 bit with the latest video drivers installed. Thanks

    PSE trial 12 installed just fine but when i start the editor it opens and shuts down after about 2 seconds without an error, the only thing that appears is a message with 'continue trial'.
    I have windows 8.1 64 bit and i already installed the latest video drivers, intel hd 4000 and nvidia geforce 710M.
    I also installed premiere elements version 12 with the same problem.
    What can be the problem here, please help?
    Thanks.
    Wim.

    Hi roberto-
    Yes, its a shame. I have also contacted lenovo support hoping that they can sort out this problem. However, first response from them was 'contact your internet service provider since internet connectivity goes down'! :-/ I am hoping I have been able to get through to them now at least about where the problem lies. I wonder if anyone has tried using the laptop with the same broadcom wireless adapter with some other version of OS (linux, windows 7 etc.) and whether they still face the same problem. I haven't tried that yet. If this is just an OS / driver issue I hope someone somewhere is working on a fix! If not, I guess the only other solution would be to get an external USB wifi adapter but that is not something one would want to do when you buy a brand new Lenovo laptop. This was a big let down for me.
    -sag

  • I m trying to download an application and receive the following message: "your request cannot be completed". What can b the problem???

    I m trying to download an application and receive the following message: "your request cannot be completed". What can b the problem???

    Your payment method may be failing. The app may be in a transitional state (not currently available for purchase).

  • My iphone 5 takes pictures alright but i can't see the photos. what can be the problem

    my iphone 5 camera takes photos alright but i dont find the photos anywhere. the photo is not saved on the phone or album. what can be the problem?

    A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process and the updater process.
    See:
    *https://support.mozilla.com/kb/Server+not+found
    *https://support.mozilla.com/kb/Firewalls
    See also:
    *http://kb.mozillazine.org/Browser_will_not_start_up

  • I keep getting an error message when I try logging into i-tunes, what can be the problem?

    I keep getting an error message when I try logging into i_tunes, what can be the problem?

    Can you say what the message is?

  • I have Lightroom 4 on a PC and while enhancing photos, the screen seems to keep refreshing. What can be the problem?

    I have Lightroom 4 on a PC and while enhancing photos, the screen seems to keep refreshing. What can be the problem?

    Leilani ~ Welcome to the Support Communities. Before posting your question it's worth searching the Communities — here's an Apple tutorial:
    Apple Support Communities: Searching
    ...But since you've already posted, look in the More Like This section to the right of your post. Also:

  • I Baught A iMac 2010 From Someone it came with lion but for the programs i use i need snow leopard but when trying to install it won't boot from usb or cd what can be the problem i've been at this for over 24 hours if anyone ca help it'd be greatly apprec

    I Baught A iMac 2010 From Someone it came with lion but for the programs i use i need snow leopard but when trying to install it won't boot from usb or cd what can be the problem i've been at this for over 24 hours if anyone ca help it'd be greatly appreciate it! Thanks!

    Downgrade OS X Lion To Snow Leopard [Video How-To]
    http://www.cultofmac.com/110614/downgrade-os-x-lion-to-snow-leopard-video-how-to /
    How To Downgrade OS X Lion To Snow Leopard: The Complete Tutorial
    http://www.redmondpie.com/how-to-downgrade-os-x-lion-to-snow-leopard-the-complet e-tutorial/
    How To Downgrade from Apple OS X Lion to Snow Leopard
    http://www.pcmag.com/article2/0,2817,2389334,00.asp

  • My iPad does not start. What can be the problem

    My iPad does not start. What can be the problem

    Does anything happens when you try to switch it on ? If not, then assuming that the battery isn't empty (and it can take up to 15 minutes of charging before it will respond), then have you tried a reset ? Press and hold both the sleep and home buttons for about 10 to 15 seconds, after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • With ios 7 switch from photo to video camera does not work neither on iphone 4 nor on ipad 3rd generation retina what can be the problem ?

    With ios 7 installed 2 days ago on my iphone 4 and on my ipad 3rd generatiion it is not possible to switch the photo camera to video camera . What is the problem ? Did someone meet the same problem ?

    Did you try swipe up and down to change?

Maybe you are looking for

  • Snow Leopard 10.6.2 - Time Synch Issue

    Hi, I have an older MBP that was just rebuilt with Snow Leopard. Everything is working fine but a weird issue I ran into which is the system time. The date and time is set in System Preferences for CST and using an NTP server. The displayed time is c

  • How to get line in audio to internal speakers

    What procedure is needed to connect line in audio to the internal speakers?  For example, playing music from my iPad through the macbook Pro's speakers. Or from any other audio source,such as a USB connector?

  • Powerbook G4 & Leopard

    I have a Powerbook G4 with the following specifications: 1.25 GHz PowerPC G4 with 512 MB DDR SBRAM. My question: is this enough to run Leopard or will the computer's overall performance be slowed so much that it won't be worth the upgrade?

  • Ibook randomly shutting down...

    Hello all, I have been experiencing a problem of my computer just shutting down at random times. This problem is not in conjunction with any other problems like freeziing or anything like that. I do not think it is a loose battery because it just shu

  • Disable "Save Password" in SQL Developer 1.5.5

    I understand from reading other threads that you can disabled the "save password" feature. This is a security feature that I must disable in our environment. The details of the previous threads were as follows: Edit the sqldeveloper/bin/sqldeveloper.