我有两个课程这里的代码
public class LoginServiceImplementation implements LoginService {
public boolean validateLogin(Login login)
{
LoginDao loginDao=DaoFactory.getLoginDao();
boolean b=loginDao.validateLogin(login);
System.out.println("id=="+login.getLoginId()+" uname=="+login.getuName()+" pass== "+login.getPassword());// values reset to null
return b;
}
}
public class LoginDaoImplementation implements LoginDao {
@Override
public Login validateLogin(Login login) {
Session session= Hibernate.getHibernateSession();
Query query= session.createQuery("from Login where uName= 'user' and password= 123");
//query.setParameter("uname", login.getuName());
//query.setParameter("pwd", login.getPassword());
//System.out.print(login.getuName());
//System.out.print(login.getPassword());
try
{
List<Login> logins=query.list();
System.out.print(logins.size());
if(logins.size()>0)
{
Login l=new Login();
l=logins.get(0);
login=l;
System.out.println("id=="+login.getLoginId()+" uname=="+login.getuName()+" pass== "+login.getPassword());/// ALL values getting printed
return login;
}
session.close();
return null;
}
catch(HibernateException x)
{
x.printStackTrace();
session.close();
return null;
}
}
}
当从 serviceImplementation 类调用 DaoImplementation 类的 validatemethod 时,DaoImplementation 类设置作为参数传递的登录对象中的值,但在 serviceimplementation 类中,我得到相同的旧对象,所有值都设置为 null。请回复原因和解决方案。谢谢你