title: Login user using JPA
body: <p>I have the following problem, in my application I would like to have some kind of login. I have following code: (Inspiration here on the web)</p>
  
  <pre><code>public boolean login(String username, String password)
      {
         try{
              EntityTransaction entr=em.getTransaction();
              entr.begin();
  
          TypedQuery&lt;Users&gt; query = em.createQuery("SELECT u FROM users u WHERE u.login = :login AND u.password = :pass", Users.class);        
          query.setParameter(1, username);
          query.setParameter(2, password); 
          try{ 
              Users u = query.getSingleResult();
              return true;
          }catch(javax.persistence.NoResultException e)
          {
              return false;
          }
          }
          finally{
          em.close();
          }
  
      }
  </code></pre>
  
  <p>When I run it and try to log in, the console will write the following message:</p>
  
  <pre><code>exception in thread "main" java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
  Exception Description: Problem compiling [SELECT u FROM users u WHERE u.login = :login AND u.password = :pass]. 
  [14, 19] The abstract schema type 'users' is unknown.
  [28, 35] The state field path 'u.login' cannot be resolved to a valid type.
  [49, 59] The state field path 'u.password' cannot be resolved to a valid type.
  </code></pre>
  
  <p>This is my table:</p>
  
  <pre><code>/*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  package com.dke.ps.Tables;
  
  import java.io.Serializable;
  import java.util.Collection;
  import java.util.Date;
  import javax.persistence.Basic;
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.ManyToOne;
  import javax.persistence.NamedQueries;
  import javax.persistence.NamedQuery;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  import javax.persistence.Temporal;
  import javax.persistence.TemporalType;
  import javax.xml.bind.annotation.XmlRootElement;
  import javax.xml.bind.annotation.XmlTransient;
  
  /**
   *
   * @author michal
   */
  @Entity
  @Table(name = "users")
  @XmlRootElement
  @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.findByLogin", query = "SELECT u FROM Users u WHERE u.login = :login")
      , @NamedQuery(name = "Users.findByPassword", query = "SELECT u FROM Users u WHERE u.password = :password")
      , @NamedQuery(name = "Users.findByEmail", query = "SELECT u FROM Users u WHERE u.email = :email")
      , @NamedQuery(name = "Users.findByDate", query = "SELECT u FROM Users u WHERE u.date = :date")})
  public class Users implements Serializable {
  
      private static final long serialVersionUID = 1L;
      @Id
      @Basic(optional = false)
      @Column(name = "userid")
      private Integer userid;
      @Column(name = "login")
      private String login;
      @Column(name = "password")
      private String password;
      @Column(name = "email")
      private String email;
      @Column(name = "date")
      @Temporal(TemporalType.DATE)
      private Date date;
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "userid")
      private Collection&lt;Saves&gt; savesCollection;
      @JoinColumn(name = "saveid", referencedColumnName = "saveid")
      @ManyToOne
      private Saves saveid;
  
      public Users() {
      }
  
      public Users(Integer userid) {
          this.userid = userid;
      }
  
      public Integer getUserid() {
          return userid;
      }
  
      public void setUserid(Integer userid) {
          this.userid = userid;
      }
  
      public String getLogin() {
          return login;
      }
  
      public void setLogin(String login) {
          this.login = login;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public Date getDate() {
          return date;
      }
  
      public void setDate(Date date) {
          this.date = date;
      }
  
      @XmlTransient
      public Collection&lt;Saves&gt; getSavesCollection() {
          return savesCollection;
      }
  
      public void setSavesCollection(Collection&lt;Saves&gt; savesCollection) {
          this.savesCollection = savesCollection;
      }
  
      public Saves getSaveid() {
          return saveid;
      }
  
      public void setSaveid(Saves saveid) {
          this.saveid = saveid;
      }
  
      @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 &amp;&amp; other.userid != null) || (this.userid != null &amp;&amp; !this.userid.equals(other.userid))) {
              return false;
          }
          return true;
      }
  
      @Override
      public String toString() {
          return "com.dke.ps.Tables.Users[ userid=" + userid + " ]";
      }
  
  }
  </code></pre>
  
  <p>As you can see, the "users" table really exists. I have no idea why it says to me, "The abstract schema type 'users' is unknown.".</p>
  
  <p>Can you help me? I think the other two errors are caused by the first one.</p>