title: Hibernate @GeneratedValue doesn't generate the Primary key before persisting the entity
body: <p>I have created a seam applcation with Hibernate(default) a ORM provider. While persisting an entity, it throws following error:</p>
  
  <pre><code>Caused by: java.sql.SQLException: Field 'COUNTRY_ID' doesn't have a default value
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
  </code></pre>
  
  <p>Its thrown because the Primary key is not generated by Hibernate before persisting entity.</p>
  
  <pre><code>@Entity
  @Table(name = "country")
  public class Country implements java.io.Serializable {
  
  private Integer countryId;
  //other instance variables...
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "COUNTRY_ID", unique = true, nullable = false)
  public Integer getCountryId() {
  return this.countryId;
  }
  
  public void setCountryId(Integer countryId) {
  this.countryId = countryId;
  }
  </code></pre>
  
  <p>When I make changes in 'Country' Table, i.e make COUNTRY.COUNTRY_ID as AUTO_INCREMENT (MySQL database) then the above code persists Country entity. Even after trying strategy </p>
  
  <pre><code>@GeneratedValue(strategy = GenerationType.IDENTITY)
  </code></pre>
  
  <p>error occurs if I don't make COUNTRY_ID as AUTO_INCREMENT.</p>
  
  <p>So, is it necessary that Primary keys should be made Auto Increment in table? Why doesn't Hibernate create a unique primary key (using HiLo algorithm) before persisting the entity if the primary key is not marked as AUTO_INCREMENT in database table.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Regards</p>