Java “春天”;“用户”;未映射

Java “春天”;“用户”;未映射,java,spring,hibernate,spring-security,Java,Spring,Hibernate,Spring Security,完成培训应用程序的第一部分后,我面临以下错误: org.springframework.security.authentication.AuthenticationServiceException: user is not mapped [from user u where u.Login = :login] 当我点击登录按钮时就会抛出。我不明白遗漏了什么,这是我的登录和DAOImpl: UserLoginDAOImpl: package school.dao; import org.hib

完成培训应用程序的第一部分后,我面临以下错误:

org.springframework.security.authentication.AuthenticationServiceException: user is not mapped [from user u where u.Login = :login]
当我点击登录按钮时就会抛出。我不明白遗漏了什么,这是我的登录和DAOImpl:

UserLoginDAOImpl:

package school.dao;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import school.model.User;

import java.util.ArrayList;
import java.util.List;

@Repository

public class UserLoginDAOImpl implements UserLoginDAO{
     @Autowired
        private SessionFactory sessionFactory;

        private Session openSession() {
            return sessionFactory.getCurrentSession();
        }

        public User getLogin(String Login) {
            List<User> userList = new ArrayList<User>();
            Query query = openSession().createQuery("from user u where u.Login = :login");
            query.setParameter("Login", Login);
            userList = query.list();
            if (userList.size() > 0)
                return userList.get(0);
            else
                return null;
        }
}
登录页面:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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"
      xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>

</h:head>
<h:body>
    <div align="right" style="">
        <h:form  id="loginFormId" prependId="false">
            <div id="loginFieldsPnlId">
                <div id="loginFieldUsrContId">
                    <h:outputText id="outTxtUserNameId" value="Username: " name="outTxtUserNameNm"></h:outputText>
                    <h:inputText id="userName" required="true" value="#{UserLoginMB.userName}" requiredMessage="Please enter username"></h:inputText>
                    <h:outputLabel id="outLblUserNameId" for="userName" name="outLblUserNameNm"></h:outputLabel>
                </div>
                <div id="loginFieldPassContId">
                    <h:outputText id="outTxtPasswordId" value="Password: " name="outTxtPasswordNm"></h:outputText>
                    <h:inputSecret id="password"  required="true" value="#{UserLoginMB.password}" requiredMessage="Please enter password" name="inTxtPasswordNm"></h:inputSecret>
                    <h:outputLabel id="outLblPasswordId" for="password" name="outLblPasswordNm"></h:outputLabel>
                </div>
            </div>
            <div id="loginBtnPanelId">
                <h:commandButton id="btnLoginId" value="Login" action="#{UserLoginMB.login}" styleClass="loginPanelBtn"></h:commandButton>
                <h:commandButton id="btnCancelId" value="Cancel" action="#{UserLoginMB.cancel}" styleClass="loginPanelBtn" immediate="true" update="loginFormId"></h:commandButton>
            </div>

        </h:form>
    </div>
    <div>
        <h:messages></h:messages>
    </div>
</h:body>
</html>

异常表示错误,
用户
类未映射

org.springframework.security.authentication.AuthenticationServiceException: user is not mapped [from **user** u where u.Login = :login]
按如下方式更新您的查询:

Query query = openSession().createQuery("from User u where u.Login = :login");

关键是
用户
用户

大多数答案和评论都表明以下几点:

Query query = openSession().createQuery("from User u where u.Login = :login");
我认为您对这一点的误解也是您的bean属性没有正确映射

GealLogin和StSt登录指的是属性“登录”而不是“登录”——请考虑重新命名您的属性为“CAMELCASE”,并相应地调整SETET/GETTER方法。 我仅使用hsqldb+hibernate5+Java8/JPA在本地运行了一个测试——在您的例子中——异常很可能被翻译,但其要点如下

  • 查询-它是用户而不是用户
  • Where子句-property(根据)应该是从访问方法setLogin和getLogin推断出的“login”
  • 将属性名称与定义的“camelCase”语义对齐

您能告诉我们用户POJO.POJO的代码吗?什么意思!?尝试
User
而不是
User
eg
queryquery Query=openSession().createQuery(“从用户u,其中u.Login=:Login”)
简单地向我们展示User.java的代码,POJO意味着一个具有成员属性和这些属性的getter&setter的类,没有其他方法(业务逻辑方法)可以尝试
Query Query=openSession().createQuery(“from User u where u.Login=:Login”)
User with caplital u
User
,结果:相同:org.springframework.security.authentication.AuthenticationServiceException:用户未映射[来自用户u,其中u.Login=:Login]@ChaibiAlaa您可以发布所有堆栈跟踪吗?除了服务器启动语句,整个堆栈跟踪在上面的帖子中。它保留了相同的错误:由:org.springframework.security.authentication.AuthenticationServiceException引起:用户未映射[从用户u,其中u.login=:login],最后一部分是您的Hibernate配置不正确和/或不包含用户类。请检查该配置并确定是否已映射到用户类中。我已经添加了我在Github上提到的裸示例-它使用Java8,因此请注意:
org.springframework.security.authentication.AuthenticationServiceException: user is not mapped [from **user** u where u.Login = :login]
Query query = openSession().createQuery("from User u where u.Login = :login");
Query query = openSession().createQuery("from User u where u.Login = :login");