Item 65: Why to Avoid the Hibernate 5 AUTO Generator Type in MySQL
Consider the following
Author entity, which relies on the Hibernate 5
AUTO generator type to generate
identifiers:
@Entity
public class AuthorBad implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
// or
@GeneratedValue
private Long id;
...
}
In MySQL and Hibernate 5, the GenerationType.AUTO generator type will result in using the TABLE generator
. This adds a significant performance penalty. The TABLE generator type doesn’t scale ...