hibernate 新增返回id
- 作者: 若尘风逐日月
- 来源: 51数据库
- 2021-01-29
public boolean inserinfo(Students stu)
{
try
{
this.session =HibernateSessionFactory.getSession();
this.tr=this.session.beginTransaction();
this.session.save(stu);
this.tr.commit();//执行了这一句肯定成功,返回True;
return true;
}
catch(Exception e)
{
return false;//抛出异常,返回False;
throw e;
}finally
{
if(this.session.Isopen)
{
this.session.close();//关闭Session;
}
}
}
Hibernate好用
搞个异常处理。未抛出异常就算成功
{
try
{
this.session =HibernateSessionFactory.getSession();
this.tr=this.session.beginTransaction();
this.session.save(stu);
this.tr.commit();//执行了这一句肯定成功,返回True;
return true;
}
catch(Exception e)
{
return false;//抛出异常,返回False;
throw e;
}finally
{
if(this.session.Isopen)
{
this.session.close();//关闭Session;
}
}
}
Hibernate好用
搞个异常处理。未抛出异常就算成功
推荐阅读