0

ログインプロセスを行うためにHibernateに問題があります。すべてのコードは、構文に関して完全に正しいです。NetBeans は、私のコードには問題がないことを教えてくれます。ただし、Web を実行してログイン プロセスをテストすると、反応せず、アドレスが doLogin にスタックされます。

すべてのクラスが正しくマッピングされました。これは私の問題です。データを取得しようとすると、コードが行に詰まってしまいます。

doLogin サーブレットで (NetBeans が提供するテンプレートを使用し、試行時にコードを入力するだけです。簡単に説明すると、次のとおりです。

Connect con = new Connect(); //my code is stucked on this line.
//I've done testing where's the cause of the stuck, and this line is the cause.
List logger = con.getLogin(username, password);

明確にするために:

Connect.java

public class Connect {
    Session sesi;

        public Connect() {
            sesi = HibernateUtil.getSessionFactory().openSession();
        }



        public List getLogin(String username, String password){
            return sesi.createQuery("from MsUser WHERE username = '"+username+"' and password = '"+password+"'").list();
        }

    }

そのクエリは HQL であるため、MsUser クラスは次のとおりです。

public class MsUser {

    public MsUser() {
    }

    private int userID;
    private String username;
    private String firstname;
    private String lastname;
    private String email;
    private String password;
    private String gender;
    private String address;
    private String phone;
    private String photo;

    public MsUser(int userID, String username, String firstname, String lastname, String email, String password, String gender, String address, String phone, String photo) {
        this.userID = userID;
        this.username = username;
        this.firstname = firstname;
        this.lastname = lastname;
        this.email = email;
        this.password = password;
        this.gender = gender;
        this.address = address;
        this.phone = phone;
        this.photo = photo;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEmail() {
        return email;
    }

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

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getPassword() {
        return password;
    }

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

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public int getUserID() {
        return userID;
    }

    public void setUserID(int userID) {
        this.userID = userID;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }


}

助けてください。しかし、主な原因として Connect のコンストラクターを疑っています。誰でも、これを引き起こしている原因を提案、修正、または教えてくれます。

付録:

HibernateUtil.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;

/**
 * Hibernate Utility class with a convenient method to get Session Factory
 * object.
 *
 * @author Ginanjar
 */
public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml) 
            // config file.
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception. 
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}
4

1 に答える 1