title: Why hibernate does not save changes to db?
body: <p>It's my configure file
  hibernate.cfg.xml</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.bytecode.use_reflection_optimizer"&gt;false&lt;/property&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;org.h2.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;1&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;
              jdbc:h2:mem:test3;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;sa&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.H2Dialect&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="hibernate.hbm2ddl.auto"&gt; create &lt;/property&gt;
          &lt;mapping resource="user.hbm.xml"&gt;&lt;/mapping&gt;
          &lt;mapping resource="role.hbm.xml"&gt;&lt;/mapping&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>When running at the first this code</p>
  
  <p><code>session.beginTransaction();</code></p>
  
  <pre><code>User stock = new User();
          User stock1 = new User();
          Role role = new Role();
          role.setId(54l);
          role.setName("student");
          session.save(role);
          stock.setBirthday(new Date(56 + 65));
          stock.setEmail("emaill");
          stock.setFirstName("dima");
          stock.setPassword("1");
          stock.setRole(role);
          System.out.println(stock.getId());
  
          stock1.setBirthday(new Date(56 + 65));
          stock1.setEmail("emassill");
          stock1.setFirstName("dima");
          stock1.setPassword("1");
          stock1.setRole(role);
          System.out.println(stock.getId());
          session.save(stock);
          session.save(stock1);
          session.getTransaction().commit();
  
          JdbcUserDao dao = new JdbcUserDao();
          System.out.println(dao.findByEmail("emassill").getFirstName());
          System.out.println(dao.findAll().get(0).getFirstName());`
  </code></pre>
  
  <p>Output is:<br>
   dima
   dima</p>
  
  <p>If I saved only one user, <code>dao.findAll().size()</code> gives "1", make a long story short, changes to db aren't saved. 
  Why is this?</p>
  
  <p>For findAll() I use DriverManager.getConnection() and so on</p>
  
  <pre><code>@Override
  public List&lt;User&gt; findAll() {
      List&lt;User&gt; result = new ArrayList&lt;User&gt;();
      try {
          connection = createConnection();
          connection.setAutoCommit(false);
          statement = connection.createStatement();
          resultSet = statement.executeQuery(FIND_ALL);
          while (resultSet.next()) {
              User temp = new User();
              temp.setId(resultSet.getLong(8));
              temp.setLogin(resultSet.getString(2));
              temp.setPassword(resultSet.getString(3));
              temp.setEmail(resultSet.getString(4));
              temp.setFirstName(resultSet.getString(5));
              temp.setLastName(resultSet.getString(6));
              temp.setBirthday(resultSet.getDate(7));
              Role tempRole = new Role();
              JdbcRoleDao jdbcRoleDao = new JdbcRoleDao();
              tempRole = jdbcRoleDao.findById(resultSet.getLong("id_role"));
              temp.setRole(tempRole);
              result.add(temp);
          }
      } catch (SQLException e) {
          myRollback();
          log.error(e, e);
          throw new RuntimeException(e);
      } finally {
          close();
      }
      return result;
  }
  
  public Connection createConnection() throws SQLException {
      url = "jdbc:h2:mem:test3;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false";// "jdbc:h2:./first";
      driver = "org.h2.Driver";
      login = "sa";
      password = "1";
      // init();
      try {
  
          Class.forName(driver);
      } catch (ClassNotFoundException e) {
          log.error(e, e);
          throw new RuntimeException(e);
      }
      Connection connection = DriverManager.getConnection(url, login,
              password);
      RunScript.execute(url, login, password, SCHEMA,
              Charset.forName("UTF-8"), false);
          return connection;
  }
  </code></pre>
  
  <p>My project used jdbcUserDao and i trying to use hibernateUserdao</p>
  
  <p>P.S.
  yes, there is text from my console:</p>
  
  <pre><code>Hibernate: alter table USER drop constraint FK_32nqg51ic2mg57ysalv1wnmdc if exists
  Hibernate: drop table ROLE if exists
  Hibernate: drop table USER if exists
  Hibernate: create table ROLE (id bigint generated by default as identity, name varchar(45) not null, primary key (id))
  Sep 29, 2014 7:49:19 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
  ERROR: HHH000389: Unsuccessful: alter table USER drop constraint FK_32nqg51ic2mg57ysalv1wnmdc if exists
  Sep 29, 2014 7:49:19 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
  ERROR: Table "USER" not found; SQL statement:
  alter table USER drop constraint FK_32nqg51ic2mg57ysalv1wnmdc if exists [42102-181]
  Hibernate: create table USER (id bigint generated by default as identity, login varchar(45) not null, password varchar(45) not null, email varchar(45) not null, first_name varchar(45) not null, last_name varchar(45) not null, birthday date not null, id_role bigint not null, primary key (id))
  Hibernate: alter table ROLE add constraint UK_9glod3qre7ighyp4ci4t6fcoy  unique (name)
  Hibernate: alter table USER add constraint UK_slockai06wyhy7i5c8vnd2o31  unique (login)
  Hibernate: alter table USER add constraint UK_oso07pudw19e66bs4yp8hwpux  unique (email)
  Hibernate: alter table USER add constraint FK_32nqg51ic2mg57ysalv1wnmdc foreign key (id_role) references ROLE
  Sep 29, 2014 7:49:19 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
  INFO: HHH000230: Schema export complete
  Hibernate: insert into ROLE (id, name) values (null, ?)
  546
  546
  Hibernate: insert into USER (id, login, password, email, first_name, last_name, birthday, id_role) values (null, ?, ?, ?, ?, ?, ?, ?)
  Hibernate: insert into USER (id, login, password, email, first_name, last_name, birthday, id_role) values (null, ?, ?, ?, ?, ?, ?, ?)
  dima
  dima
  </code></pre>
  
  <p>public class User {
      private Long id;
      ...
      public String getFirstName() {
          return firstName;
      }</p>
  
  <pre><code>....
  
  public String getPassword() {
      return password;
  }
  
  public void setBirthday(Date arg0) {
      birthday = arg0;
  }
  
  public void setFirstName(String arg0) {
      firstName = arg0;
  }
  </code></pre>
  
  <p>...
  }
  Role similar</p>