在向Dao层注入entity时候总是报错,加入需要注入的属性的get方法后解决了,这是因为什么原因?
1.在向Dao层注入entity类时候总是报错:Error creating bean with name 'todayAttendanceDao' defined in class path resource [springxml/yhspring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'todayAttendance' of bean class [com.chinasofti.dao.impl.yh.TodayAttendanceDaoImpl]: Bean property 'todayAttendance' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
2.经过检查没有发现entity层和dao层有什么错误,在Dao层加入属性的get方法后,不再报错。
3.spring.xml :
对应Dao层 :
Configuration cfg = new Configuration().configure();
SessionFactory sf = cfg.buildSessionFactory();
Session session = sf.openSession();
private TodayAttendance todayAttendance = null;
public void setTodayAttendance(TodayAttendance todayAttendance) {
this.todayAttendance = todayAttendance;
}
public TodayAttendance getTodayAttendance() {
return todayAttendance;
}//加入这个get方法后就不报错了?为什么?是因为我dao层里面有方法的互调吗?
public void update(TodayAttendance currentAttendance) {
//如果有记录则更新,没有则创建
todayAttendance = getTodayAttendance(currentAttendance.getUid());
if(todayAttendance != null){
//有记录,更新
todayAttendance.setLate(todayAttendance.getLate()+currentAttendance.getLate());
todayAttendance.setAbsenteeism(todayAttendance.getAbsenteeism()+currentAttendance.getAbsenteeism());
todayAttendance.setWorkover(todayAttendance.getWorkover()+currentAttendance.getWorkover());
session.update(todayAttendance);
}else{
//没记录,插入
session.save(currentAttendance);
}
}
public TodayAttendance getTodayAttendance(int uId) {
//通过uId得到TodayAttendance
String hql = "from TodayAttendance where uId = "+uId;
Query query = session.createQuery(hql);
List list = query.list();
if(list.size() > 0){
todayAttendance = (TodayAttendance)list.get(0);
System.out.println(todayAttendance.getTid());
return todayAttendance;
}else{
return null;
}
}
public void clear() {
//得到todayAttendance表所有数据
String hql = "from TodayAttendance";
Query query = session.createQuery(hql);
List list = query.list();
for(int i = 0;i < list.size();i++){
TodayAttendance attendanceToDelete = (TodayAttendance)list.get(i);
System.out.println("111");
session.delete(attendanceToDelete);
System.out.println("222");
}
}
4.不知道为什么就不报错了,也不知道为什么需要些get方法,折腾半天了,是跟我update方法里面调用getTodayAttendance方法有关吗?
相关阅读:
做wordpress需要主机空间和域名,主机空间要怎么操作?
微信开发用户与公众号的交互信息一般都需要存储吗
gunicorn reload选项为什么是无效的呢?
Visual Studio Team Services 如何将英文界面改为中文??
scrapy 如何知晓本次爬取所用流量?
两个网站之间,如何通讯比较安全?
Java真数组
我的chrome好像被嵌入脚本了,但是我找不到这段脚本哪执行的?
请问一下在移动端浏览器中,如何调用其他APP
如何把Linux下的源码编译成Windows的DLL?
nginx rewrite /js /css /css/image /template
使用localhost:4000访问本地blog一直无响应
腾讯微博api,无法使用notice/app_notice 发送通知的api
怎么让一张html页面适应不同屏幕大小的设备??
CentOS 7 Docker启动服务失败
SQLite3怎么存入vector 类型
mysql大表or小表?
当目标activity的launchMode为singleTask时,如何向源Activity返回数据?
NSAnimationContext 动不起来
C++居然能用父类指针(里面存的也是父类)调用子类(子类独有的)函数?