public void savePerson(Person person)
{
Session session=HibernateUtil.openSession();
System.out.println("PersonDAOImpl-------------here");
Transaction tx=session.beginTransaction();
System.out.println("..............under PersonDAOImpl!");
System.out.println(person.getUsername()+" "+person.getPassword()+" "+person.getAge()+" "+person.getRegisteDate());;
try
{
System.out.println("-----------PersonDAOImpl---------------");
System.out.println(person.getUsername()+" "+person.getPassword()+" "+person.getAge()+" "+person.getRegisteDate());;
session.save(person);
System.out.println("-----------------behind person------------------");
}
catch(Exception ex)
{
System.out.println("------------PersonDAOImpl exception!");
ex.printStackTrace();
if(null!=tx)
{
tx.rollback();
}
}
finally
{
HibernateUtil.close(session);
}
}
输出的sql代码只有:Hibernate: select max(id) from person,没有insert代码,没有写入到数据库,求高手帮助解决!!!
------解决方案--------------------
好像没有commit啊?
这句Hibernate: select max(id) from person是其他代码中的吧
你的输出信息好多啊
------解决方案--------------------
try
{
System.out.println("-----------PersonDAOImpl---------------");
System.out.println(person.getUsername()+" "+person.getPassword()+" "+person.getAge()+" "+person.getRegisteDate());;
session.saveOrUpdate(person);
System.out.println("person id:"+person.getId());
//如果有id说明保存成功。
System.out.println("-----------------behind person------------------");
}