Sunday, October 4, 2009

Cross Platform Hibernate @Id Sequence setting

Cross platform @Id setting
@SequenceGenerator(name = "SEQ_HRMS_EMP", sequenceName = "SEQ_HRMS_EMP", initialValue = 1, allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_HRMS_EMP")
@Column(name = "user_id")
private Integer userId;

Schema export from hibernate
  1. MySql
    create table HRMS_EMP (
    user_id integer not null auto_increment,

    MySql will ignore the generator = "SEQ_HRMS_EMP" setting because MySql does not have sequence.
  2. Postgres
    create sequence SEQ_HRMS_EMP;
  3. Oracle
    create sequence SEQ_HRMS_EMP;

No comments: