java.lang.ClassCastException: cn.study.model.User_$$_javassist_0 cannot be cast to javassist.util.pr

java.lang.ClassCastException: cn.study.model.User_$$_javassist_0 cannot be cast to javassist.util.pr_第1张图片

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//addEmployee();
		//修改用户
		//获取一个会话
		Session session=MySessionFactory.getSessionFactory().openSession();
		
		Transaction ts=session.beginTransaction();
		//修改用户1.获取要修改的用户2.修改
		//load是通过主键属性,获取该对象的实例<--表的记录对应-->
		Employee emp=(Employee) session.load(Employee.class, 3);
		emp.setName("彩霞");
		emp.setEmail("[email protected]");
		ts.commit();session.close();
		
	}


解决方法:将load改成get即可:

Transaction ts=session.beginTransaction();
		//修改用户1.获取要修改的用户2.修改
		//load是通过主键属性,获取该对象的实例<--表的记录对应-->
		Employee emp=(Employee) session.get(Employee.class, 3);


你可能感兴趣的:(java.lang.ClassCastException: cn.study.model.User_$$_javassist_0 cannot be cast to javassist.util.pr)