我用的是通用Dao,但是保存方法可以执行,可以保存到数据库,但是更新方法虽然执行了,但是数据却没有更新,这是怎么回事啊,控制台也已经输出了更新语句,就是数据库的数据不更新,代码见下图,求教啊
8条回答 默认 最新
- 二哈大叔 2017-02-18 14:00关注
这是我dao层实现类的代码
package com.ffour.yixing.dao.impl;import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;import javax.annotation.Resource;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;import com.ffour.yixing.dao.interfaces.BaseDao;
@SuppressWarnings("unchecked")
public class BaseDaoImpl implements BaseDao{private Class<T> clazz; /** * 通过构造方法指定DAO的具体实现类 */ public BaseDaoImpl() { ParameterizedType type = (ParameterizedType) this.getClass().getGenericSuperclass(); clazz = (Class<T>) type.getActualTypeArguments()[0]; System.out.println("DAO的真实实现类是:" + this.clazz.getName()); } /** * 向DAO层注入SessionFactory */ @Resource private SessionFactory sessionFactory; /** * 获取当前工作的Session */ protected Session getSession() { return this.sessionFactory.getCurrentSession(); } @Override public void save(T entity) { // TODO Auto-generated method stub this.getSession().save(entity); this.getSession().flush(); } @Override public void update(T entity) { // TODO Auto-generated method stub this.getSession().update(entity); System.out.println("111"); this.getSession().flush(); } @Override public void delete(Serializable id) { // TODO Auto-generated method stub this.getSession().delete(this.findById(id)); this.getSession().flush(); } @Override public T findById(Serializable id) { // TODO Auto-generated method stub return (T) this.getSession().get(this.clazz, id); } @Override public List<T> findByHQL(String hql, Object... params) { // TODO Auto-generated method stub Query query = this.getSession().createQuery(hql); for (int i = 0; params != null && i < params.length; i++) { query.setParameter(i, params[i]); } return query.list(); }
}
解决 无用评论 打赏 举报
悬赏问题
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记
- ¥15 保护模式-系统加载-段寄存器
- ¥15 电脑桌面设定一个区域禁止鼠标操作
- ¥15 求NPF226060磁芯的详细资料