Hibernate org.hibernate.exception.SQLGrammarException

时间:2015-09-15 17:33:25

标签: hibernate

我正在使用Hibernate和Struts2来创建登录页面。在下面的代码中,我试图从LoginTable获取数据,其中userName和password是两个动态变量。

          String hql = "from LoginTable as log where log.userId=:userName and     log.password=:passw";
          Query query = session.createQuery(hql);
          query.setString("userName", userName);
          query.setString("passw", passw);
          List result = query.list();

LoginTable代码:

            import javax.persistence.Column;
            import javax.persistence.Entity;
            import javax.persistence.GeneratedValue;
            import javax.persistence.Id;
            import javax.persistence.Table;

            @Entity
            @Table(name="user_details")
            public class LoginTable {  
              @Id
              @GeneratedValue
              private int id;
              @Column(name="user_id")
              private String userId;

              @Column(name="password")
              private String password;

              @Column(name="user_nm")
              private String userName;

              @Column(name="designation")
              private String designation;

              @Column(name="email")
              private String email;

              @Column(name="mobile")
              private String mobile;

              @Column(name="user_privilege")
              private String userPriviledge;

              @Column(name="first_login")
              private String firstLogin;

              @Column(name="password_status")
              private String passwordStatus;

              public String getUserId() {
                return userId;
              }

              public void setUserId(String userId) {
                this.userId = userId;
              }

              public String getPassword() {
                return password;
              }

              public void setPassword(String password) {
                this.password = password;
              }

              public String getUserName() {
                return userName;
              }

              public void setUserName(String userName) {
                this.userName = userName;
              }

              public String getDesignation() {
                return designation;
              }

              public void setDesignation(String designation) {
                this.designation = designation;
              }

              public String getEmail() {
                return email;
              }

              public void setEmail(String email) {
                this.email = email;
              }

              public String getMobile() {
                return mobile;
              }

              public void setMobile(String mobile) {
                this.mobile = mobile;
              }

              public String getUserPriviledge() {
                return userPriviledge;
              }

              public void setUserPriviledge(String userPriviledge) {
                this.userPriviledge = userPriviledge;
              }

              public String getFirstLogin() {
                return firstLogin;
              }

              public void setFirstLogin(String firstLogin) {
                this.firstLogin = firstLogin;
              }

              public String getPasswordStatus() {
                return passwordStatus;
              }

              public void setPasswordStatus(String passwordStatus) {
                this.passwordStatus = passwordStatus;
              }  
            }

但是在执行上面的代码之后我得到了以下异常。 org.hibernate.exception.SQLGrammarException:无法执行查询

我只得到了SQLGrammarException。

0 个答案:

没有答案