一:public void updateNewsType(FcNewstype fcntype)
{
session=HibernateSessionFactory.getSession();
try {
session.beginTransaction();
session.update(FcNewstype.class, fcntype.getNewsTpeId());
session.beginTransaction().commit();
session.close();
} catch (Exception e) {
System.out.println(e.getMessage());
session.close();
}
}这事我写的一个测试update方法的方法,事务也开启提交了,数据库中就是不更新,提示:Unknown entity: java.lang.Class。二:public void updateNewsType(FcNewstype fcntype)
{
session=HibernateSessionFactory.getSession();
try {
session.beginTransaction();
session.update(FcNewstype.class, fcntype.getNewsTpeId());
session.beginTransaction().commit();
session.close();
} catch (Exception e) {
System.out.println(e.getMessage());
session.close();
}
}
情况和一一样:数据库不更新,Unknown entity: java.lang.Class。
然后我换了三:public void updateNewsType(FcNewstype fcntype)
{
session=HibernateSessionFactory.getSession();
try {
session.beginTransaction();
session.update(fcntype, fcntype.getNewsTpeId());
session.beginTransaction().commit();
session.close();
} catch (Exception e) {
System.out.println(e.getMessage());
session.close();
}
}
数据库还是不更新,什么都不提示了,郁闷。
我用的hibernate和struts框架,没有用spring框架,而且save方法可以插入数据,get方法可以得到数据,唯独update不能更新数据……

解决方案 »

  1.   

    session.getTransaction().commit(); 不要重新启动事务了。而且,为啥不直接update?session.update(fcntype); 
      

  2.   

    补充下,上面的“二”那个地方的:session.update(FcNewstype.class, fcntype.getNewsTpeId()); 
    应该是:session.update(FcNewstype, fcntype.getNewsTpeId()); 
    FcNewsType后面没有.class
      

  3.   


    刚试过,直接update还是不行……
      

  4.   


    解决了啦………………按照你说的直接update(fcntype);
    但是还得开启事务提交才能更新数据库。