I'm using hibernate annotations, my database in is MySQL.
I tried to persist a bunch of objects and commit at the end, which means insert all or insert none of them.
For example, I want to insert 10 objects one time, if exception happens at the 9th object, because I didn't do commit, there should be no new data in database. However, I do find the 8 datas. Anyone has experience/solution for this?
BTW, I didn't use Spring.
Code:
       try{                
           for (Student student : students)
              {      
                 studentDAO.save(student);         
              }//end loop      
         studentDAO.commitTransaction(); //insert to do as one atomic transaction, if failes - DO NOT DO ANY INSERT      
      }catch(Exception e)
      {
         studentDAO.rollback();      
      }finally
      {
         studentDAO.close();
      }
Here's some of my hibernation configuration:
Code:
   config.setProperty("hibernate.connection.pool_size", "10");
            config.setProperty("hibernate.connection.autocommit", "false");
            config.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");                 
            config.setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");
            config.setProperty("hibernate.current_session_context_class", "thread");