Running com.mycompany.app.service.UserServiceTest
**********service 层testQueryPassword******开始******
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.081 sec <<< FAILURE!
testQueryPassword(com.mycompany.app.service.UserServiceTest) Time elapsed: 0.022 sec <<< ERROR!
java.lang.NullPointerException
public String getUserPassword(String userName) {
String name = "";
Session session = null;
try {
session = HibernateUtils.getSession();
session.beginTransaction();
List result = session.createQuery("select password from User where name = :name").setParameter("name", userName).list();
if(result !=null && result.size()>0) {
name = (String) result.get(0);
} else {
name = "null";
}
System.out.println("****************************");
System.out.println(name);
session.getTransaction().commit();
}catch(Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
}finally {
HibernateUtils.closeSession(session);
}
return "zhanshan";
}
}
//service层
package com.mycompany.app.service;
import com.mycompany.app.dao.UserDao;
public class UserServiceImpl implements UserService {
private UserDao userdao;
public String getUserPassword(String name) {
// TODO Auto-generated method stub
return userdao.getUserPassword(name);
}
}