EclipseLink JPA 用户名/密码查找会删除运行应用程序的记录



我正在使用 apache shiro 对用户进行身份验证,我想简单地将用户名打印到我的控制台以检查我的 finder 功能是否正常工作,似乎当我向用户添加记录时(使用 sql 语句而不是 eclipseLink,当应用程序运行时记录被删除?

以下是我尝试按用户名检索单个用户的方式:

protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
    UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
    Map<String, String> map = new HashMap<String, String>();
    String tempUsername = token.getUsername();
    String password = "";
    Users user;
    // Null username is invalid
    if (tempUsername == null) {
        throw new AccountException("Null usernames are not allowed by this realm.");
    }
    AuthenticationInfo info = null;
    // this will query and find the users by the specified username and then return us the single result
    user = getAuthorizedUser(Users.findUsersesByUsernameEquals(tempUsername));
    System.out.print(user.getUsername());
    System.out.println("yea the username = ");
    password = user.getPassword();
    info = buildAuthenticationInfo(tempUsername, password.toCharArray());
    return info;
}
/*Build the required authentication info; Replace with SaltAuthenticationInfo for salted passwords*/
protected AuthenticationInfo buildAuthenticationInfo(String username, char[] password) {
          return new SimpleAuthenticationInfo(username, password, getName());
}
protected Users getAuthorizedUser(TypedQuery<Users> q){
    System.out.println("working authentication");
      return q.getSingleResult(); 
}

这是因为我没有使用 JPA 来持久化和添加用户,而是在我的应用程序之外编写 sql 语句吗?

我禁用了此属性<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

这是删除我的测试记录并解决了我的问题。

最新更新