dao.getSession()可能这个返回的是null
自己查下
自己查下
解决方案 »
- Vector 的问题
- 快逸报表参数问题!急!!
- 怎样让servlet运行后执行某一个操作?
- Hibernate怎么动态修改hbm.xml中table的名字?
- 网站后台如何做
- 数据库链接Connection能被共享吗?
- jsp中sql2000的连接出了什么问题?(Error establishing socket) 急!在线等!
- (在线等待,问题解决立刻给分)struts关于动态 radio 与 multibox 的问题.
- 请给个你实际开发中应用到的ejb例子,并附说明及怎样用,谢谢。
- 关于weblogic的数据源问题。``
- 用java写即时通讯软件
- spring+ibatis配置问题!急急!!!
你该成dao。getDao()试一下看可以不
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;/**
* Data access object (DAO) for domain model class User.
*
* @see com.borry.struts.User
* @author MyEclipse Persistence Tools
*这是DAO的代吗
*/public class UserDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(UserDAO.class); public void save(User transientInstance) {
log.debug("saving User instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
} public void delete(User persistentInstance) {
log.debug("deleting User instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
} public User findById(java.lang.Integer id) {
log.debug("getting User instance with id: " + id);
try {
User instance = (User) getSession()
.get("com.borry.struts.User", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
} public List findByExample(User instance) {
log.debug("finding User instance by example");
try {
List results = getSession().createCriteria("com.borry.struts.User")
.add(Example.create(instance)).list();
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
} public List findByProperty(String propertyName, Object value) {
log.debug("finding User instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from User as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
} public List findAll() {
log.debug("finding all User instances");
try {
String queryString = "from User";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
} public User merge(User detachedInstance) {
log.debug("merging User instance");
try {
User result = (User) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
} public void attachDirty(User instance) {
log.debug("attaching dirty User instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
} public void attachClean(User instance) {
log.debug("attaching clean User instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}UserDAO dao = new Save().getDao();
改成 UserDAO dao = UserDAO()
还是不行