为什么我的页面能跳转成功而在数据库中查不到数据? 为什么我的页面能跳转成功而在数据库中查不到数据? 希望大家帮帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 此回复为自动发出,仅用于显示而已,并无任何其他特殊作用楼主【w87179128】截止到2008-07-04 12:56:45的历史汇总数据(不包括此帖):发帖的总数量:2 发帖的总分数:25 结贴的总数量:0 结贴的总分数:0 无满意结贴数:0 无满意结贴分:0 未结的帖子数:2 未结的总分数:25 结贴的百分比:0.00 % 结分的百分比:0.00 % 无满意结贴率:---------------------无满意结分率:---------------------如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html 你说得也太笼统了吧,估计是用hib却没有正确保存对象 我数据库错做的类是myeclipse自己生成的啊。。package com.wang.hibernate.DAO;import java.util.List;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;import com.wang.hibernate.Userinfo;public class UserinfoDAO extends BaseHibernateDAO { private static final Log log = LogFactory.getLog(UserinfoDAO.class); // property constants public static final String USERNAME = "username"; public static final String PASSWORD = "password"; public static final String SEX = "sex"; public static final String TEL = "tel"; public static final String EMAIL = "email"; public static final String ROLE = "role"; public static final String QQ = "qq"; public void save(Userinfo transientInstance) { log.debug("saving Userinfo instance"); try { getSession().save(transientInstance); log.debug("save successful"); } catch (RuntimeException re) { log.error("save failed", re); throw re; } } public void delete(Userinfo persistentInstance) { log.debug("deleting Userinfo instance"); try { getSession().delete(persistentInstance); log.debug("delete successful"); } catch (RuntimeException re) { log.error("delete failed", re); throw re; } } public Userinfo findById(java.lang.Integer id) { log.debug("getting Userinfo instance with id: " + id); try { Userinfo instance = (Userinfo) getSession().get( "com.wang.hibernate.Userinfo", id); return instance; } catch (RuntimeException re) { log.error("get failed", re); throw re; } } public List findByExample(Userinfo instance) { log.debug("finding Userinfo instance by example"); try { List results = getSession().createCriteria( "com.wang.hibernate.Userinfo") .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 Userinfo instance with property: " + propertyName + ", value: " + value); try { String queryString = "from Userinfo 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 findByUsername(Object username) { return findByProperty(USERNAME, username); } public List findByPassword(Object password) { return findByProperty(PASSWORD, password); } public List findBySex(Object sex) { return findByProperty(SEX, sex); } public List findByTel(Object tel) { return findByProperty(TEL, tel); } public List findByEmail(Object email) { return findByProperty(EMAIL, email); } public List findByRole(Object role) { return findByProperty(ROLE, role); } public List findByQq(Object qq) { return findByProperty(QQ, qq); } public List findAll() { log.debug("finding all Userinfo instances"); try { String queryString = "from Userinfo"; Query queryObject = getSession().createQuery(queryString); return queryObject.list(); } catch (RuntimeException re) { log.error("find all failed", re); throw re; } } public Userinfo merge(Userinfo detachedInstance) { log.debug("merging Userinfo instance"); try { Userinfo result = (Userinfo) getSession().merge(detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } } public void attachDirty(Userinfo instance) { log.debug("attaching dirty Userinfo instance"); try { getSession().saveOrUpdate(instance); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public void attachClean(Userinfo instance) { log.debug("attaching clean Userinfo instance"); try { getSession().lock(instance, LockMode.NONE); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } }} 这个是我的类package com.wang.struts.action;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import com.wang.hibernate.Userinfo;import com.wang.hibernate.DAO.UserinfoDAO;import com.wang.struts.form.RegistForm;public class RegistAction extends Action { /* * Generated Methods */ UserinfoDAO userinfoDao; public UserinfoDAO getUserinfoDao() { return userinfoDao; } public void setUserinfoDao(UserinfoDAO userinfoDao) { this.userinfoDao = userinfoDao; } public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { RegistForm regist = (RegistForm)form; Userinfo userinfo =new Userinfo(); userinfo.setUserid(regist.getUserid()); userinfo.setUsername(regist.getUsername()); userinfo.setPassword(regist.getPassword()); userinfo.setSex(regist.getSex()); userinfo.setEmail(regist.getEmail()); userinfo.setRole(regist.getRole()); userinfo.setTel(regist.getTel()); userinfo.setQq(regist.getQq()); userinfoDao.save(userinfo); return mapping.findForward("reg_suc"); }} 这么说吧,你要保存的对象在hib中根本不存在,你要hib怎么保存?应该先把这个对象先找出来再updata,应该就是这种错误 还有一种情况就是id是自增的,但是xml中设置错误了 我的userid 设置的increment 但是在页面上并没有获得他。。该怎么做呀? 在对象xml里加入<generator class="identity" />例子id name="unitId" type="java.lang.Integer"> <column name="Unit_id" /> <generator class="identity" /> 小白请教: 关于 index.jsp 中 isValid() == false的错误。 就剩20分了...对不住各位了>.< 如何获得spring加载的Bean对象,求助 jstl在当前页面如何判断 checkbox状态 MQ服务器 向远程队列发送消息 ★★★JSP项目在eclipse之外无法运行 webwork+spring+hibernate,应该这样写才正确呢 spring 调用oracle存储过程?? 关于httpunit抓取动态网页的小问题 web service快速入门 求EJB方面的好书! jni 如何调用已编译的dll 在Spring里配置aop出现问题请帮忙看看谢谢!
楼主【w87179128】截止到2008-07-04 12:56:45的历史汇总数据(不包括此帖):
发帖的总数量:2 发帖的总分数:25
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:2 未结的总分数:25
结贴的百分比:0.00 % 结分的百分比:0.00 %
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
package com.wang.hibernate.DAO;import java.util.List;
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;import com.wang.hibernate.Userinfo;
public class UserinfoDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(UserinfoDAO.class);
// property constants
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public static final String SEX = "sex";
public static final String TEL = "tel";
public static final String EMAIL = "email";
public static final String ROLE = "role";
public static final String QQ = "qq"; public void save(Userinfo transientInstance) {
log.debug("saving Userinfo instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
} public void delete(Userinfo persistentInstance) {
log.debug("deleting Userinfo instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
} public Userinfo findById(java.lang.Integer id) {
log.debug("getting Userinfo instance with id: " + id);
try {
Userinfo instance = (Userinfo) getSession().get(
"com.wang.hibernate.Userinfo", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
} public List findByExample(Userinfo instance) {
log.debug("finding Userinfo instance by example");
try {
List results = getSession().createCriteria(
"com.wang.hibernate.Userinfo")
.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 Userinfo instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Userinfo 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 findByUsername(Object username) {
return findByProperty(USERNAME, username);
} public List findByPassword(Object password) {
return findByProperty(PASSWORD, password);
} public List findBySex(Object sex) {
return findByProperty(SEX, sex);
} public List findByTel(Object tel) {
return findByProperty(TEL, tel);
} public List findByEmail(Object email) {
return findByProperty(EMAIL, email);
} public List findByRole(Object role) {
return findByProperty(ROLE, role);
} public List findByQq(Object qq) {
return findByProperty(QQ, qq);
} public List findAll() {
log.debug("finding all Userinfo instances");
try {
String queryString = "from Userinfo";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
} public Userinfo merge(Userinfo detachedInstance) {
log.debug("merging Userinfo instance");
try {
Userinfo result = (Userinfo) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
} public void attachDirty(Userinfo instance) {
log.debug("attaching dirty Userinfo instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
} public void attachClean(Userinfo instance) {
log.debug("attaching clean Userinfo instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}
package com.wang.struts.action;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;import com.wang.hibernate.Userinfo;
import com.wang.hibernate.DAO.UserinfoDAO;
import com.wang.struts.form.RegistForm;public class RegistAction extends Action {
/*
* Generated Methods
*/
UserinfoDAO userinfoDao;
public UserinfoDAO getUserinfoDao() {
return userinfoDao;
}
public void setUserinfoDao(UserinfoDAO userinfoDao) {
this.userinfoDao = userinfoDao;
} public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
RegistForm regist = (RegistForm)form;
Userinfo userinfo =new Userinfo();
userinfo.setUserid(regist.getUserid());
userinfo.setUsername(regist.getUsername());
userinfo.setPassword(regist.getPassword());
userinfo.setSex(regist.getSex());
userinfo.setEmail(regist.getEmail());
userinfo.setRole(regist.getRole());
userinfo.setTel(regist.getTel());
userinfo.setQq(regist.getQq());
userinfoDao.save(userinfo);
return mapping.findForward("reg_suc");
}
}
例子id name="unitId" type="java.lang.Integer">
<column name="Unit_id" />
<generator class="identity" />