RT

解决方案 »

  1.   

    在hibernate的.cfg.xml中配置显示sql语句,当对象持久化到数据库时在控制台会看到Hibernate:insert into....字样
      

  2.   

    hibernate.show_sql true
    这是在.property文件中的写法
    更新一条记录控制台会输出
    Hibernate: update T_DRAFTOFFICEFORM set C_CONTENT=?, C_CREATETIME=?, C_USERID=?, C_TITLE=?, C_TYPE=? where C_ID=?
      

  3.   

    单元测试用junit
    import junit.framework.TestCase;public class HiberTest extends TestCase { protected void setUp() throws Exception {
    super.setUp();
    } protected void tearDown() throws Exception {
    super.tearDown();
    }

    public void testCritial(){
    Session session = null;
    Transaction tran = null;
    try{
    session = HibernateSessionFactory.getSession();
    Criteria cri = session.createCriteria(User.class);
    User user = new User();
    user.setName("spring");
    user.setPassword("java22");

    Example exa = Example.create(user);
    cri.add(exa);

    List list = cri.list();
    if (list.size() == 1){
    System.out.println("login success");
    }else{
    System.out.println("login failure");
    }
    //tran = session.beginTransaction();

    }catch(Exception e){
    System.out.println(e);
    //tran.rollback();
    }finally{
    if (session != null){
    session.close();
    }
    }
    }
      

  4.   

    自己再顶
    可能是我叙述的问题不清楚。再重新叙述一遍:..
         由于hibernate.session.save等持久化方法的返回值为void,我无法判断我是否持久化成功,不知道在座各位是如何解决这个问题的
      

  5.   

    做个测试类,调用一下dao的方法就可以了。
      

  6.   

    在hibernate.cfg.xml中加入
    <property name="show_sql">true </property>
    当执行save方法时,如果持久化成功会在后台打印hql语句insert ...............