Hibernate session.flush() even though autocommit is set
<p>I realised to need to call session.flush() for entities whose primary key is not a GeneratedValue before they are persisted in the database. And I have to do this even though I have already autocommit set to true.
Here is my hibernate configuration </p>

<pre><code>&lt;property name="hibernate.dialect"&gt;${hibernate.dialect}&lt;/property&gt;
&lt;property name="hibernate.connection.driver_class"&gt;${hibernate.connection.driver_class}&lt;/property&gt;
&lt;property name="hibernate.connection.url"&gt;${hibernate.connection.url}&lt;/property&gt;
&lt;property name="hibernate.connection.username"&gt;${hibernate.connection.username}&lt;/property&gt;
&lt;property name="hibernate.connection.password"&gt;${hibernate.connection.password}&lt;/property&gt;
&lt;property name="connection.autocommit"&gt;true&lt;/property&gt;
</code></pre>

<p>and here is an example for the entity for which i need to call session.flush() after in code after saving before it gets persisted</p>

<pre><code>    @Id
    @Column(name = "MembTypeCode")
    private String memTypeCode;
    @Column(name = "MemberType")
    private String memberType;
  ...
</code></pre>

<p>but for entities whose Id is a GeneratedValue (like the one below), I do not need to call session.flush() in code after saving in order for it to get persisted in the database because i have autocommit set to true.</p>

<pre><code>@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "PrescriptId")
private int prescriptId;
@Column(name = "InvNum")
private Integer invNum;
@Column(name = "DocType")
private String docType;
...
</code></pre>

<p>Can someone please explain to me why I am experiencing this? I'm using Hibernate 4.1.0.FINAL</p>