title: session.save doesn't save to the database
body: <p>Here is the JUnit code:</p>
  
  <pre><code>package com.learn.hibernate.entities;
  
  import java.util.Date;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.service.ServiceRegistry;
  import org.hibernate.service.ServiceRegistryBuilder;
  import org.junit.After;
  import org.junit.Before;
  import org.junit.Test;
  
  public class HibernateTest {
  
      private SessionFactory sessionFactory;
      private Session session;
      private Transaction transaction;
  
      @Before
      public void init() {
          System.out.println("before");
          Configuration configuration = new Configuration().configure();
          ServiceRegistry serviceRegistry = 
                  new ServiceRegistryBuilder().applySettings(configuration.getProperties())
                                              .buildServiceRegistry();
          sessionFactory = configuration.buildSessionFactory(serviceRegistry);
          session = sessionFactory.openSession();
          transaction = session.beginTransaction();
      }
  
      @After
      public void destory() {
          System.out.println("after");
          transaction.commit();
          session.close();
          sessionFactory.close();
      }
  
      @Test
      public void testSessionFlush() {
          News news = new News("Java2", "Sun2", new Date());
          session.save(news);
          System.out.println("end");
      }
  }
  </code></pre>
  
  <p>Here is the result:</p>
  
  <pre><code>Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 
  before
  September 26, 2015 8:10:08 Afternoon org.hibernate.annotations.common.Version &lt;clinit&gt;
  INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
  September 26, 2015 8:10:08 Afternoon org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {4.2.4.Final}
  September 26, 2015 8:10:08 Afternoon org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  September 26, 2015 8:10:08 Afternoon org.hibernate.cfg.Environment buildBytecodeProvider
  INFO: HHH000021: Bytecode provider name : javassist
  September 26, 2015 8:10:08 Afternoon org.hibernate.cfg.Configuration configure
  INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
  September 26, 2015 8:10:08 Afternoon org.hibernate.cfg.Configuration getConfigurationInputStream
  INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
  September 26, 2015 8:10:08 Afternoon org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
  WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
  September 26, 2015 8:10:08 Afternoon org.hibernate.cfg.Configuration addResource
  INFO: HHH000221: Reading mappings from resource: com/learn/hibernate/entities/News.hbm.xml
  September 26, 2015 8:10:08 Afternoon org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
  WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
  September 26, 2015 8:10:08 Afternoon org.hibernate.cfg.Configuration doConfigure
  INFO: HHH000041: Configured SessionFactory: null
  September 26, 2015 8:10:08 Afternoon org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
  September 26, 2015 8:10:08 Afternoon org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000115: Hibernate connection pool size: 20
  September 26, 2015 8:10:08 Afternoon org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000006: Autocommit mode: false
  September 26, 2015 8:10:08 Afternoon org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql:///hibernate5]
  September 26, 2015 8:10:08 Afternoon org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000046: Connection properties: {user=root, password=****}
  September 26, 2015 8:10:09 Afternoon org.hibernate.dialect.Dialect &lt;init&gt;
  INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
  September 26, 2015 8:10:09 Afternoon org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
  INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
  September 26, 2015 8:10:09 Afternoon org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
  INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
  September 26, 2015 8:10:09 Afternoon org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory &lt;init&gt;
  INFO: HHH000397: Using ASTQueryTranslatorFactory
  September 26, 2015 8:10:09 Afternoon org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000228: Running hbm2ddl schema update
  September 26, 2015 8:10:09 Afternoon org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000102: Fetching database metadata
  September 26, 2015 8:10:09 Afternoon org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000396: Updating schema
  September 26, 2015 8:10:09 Afternoon org.hibernate.tool.hbm2ddl.TableMetadata &lt;init&gt;
  INFO: HHH000261: Table found: hibernate5.NEWS
  September 26, 2015 8:10:09 Afternoon org.hibernate.tool.hbm2ddl.TableMetadata &lt;init&gt;
  INFO: HHH000037: Columns: [date, author, id, title]
  September 26, 2015 8:10:09 Afternoon org.hibernate.tool.hbm2ddl.TableMetadata &lt;init&gt;
  INFO: HHH000108: Foreign keys: []
  September 26, 2015 8:10:09 Afternoon org.hibernate.tool.hbm2ddl.TableMetadata &lt;init&gt;
  INFO: HHH000126: Indexes: [primary]
  September 26, 2015 8:10:09 Afternoon org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000232: Schema update complete
  after
  </code></pre>
  
  <p>As you could see, though I asked to output <code>end</code> after <code>save()</code>, the result didn't contain it. And the database didn't change, why?</p>