Posts

Hibernate Sequence Generator using database sequence

Hello friends, In hibernate many of us face difficulties in linking database sequence with java class. We want that whenever row inserted by hibernate, it should use the sequence present in database (which was created by our-self) and NOT default hibernate generated  'hibernate_sequence' Follow these simple steps to link your database sequence with hibernate (Using Sequence generation strategy) 1.Create sequence in the database. 2.Create java class with with jpa/hibernate annotations You can insert the row in database table directly or through hibernate, this sequence will work without any gaps. Example @Id @Column(name = "SeqId") @GeneratedValue(strategy = GenerationType.SEQUENCE , generator = "INTE_SEQ") @GenericGenerator(name = "INTE_SEQ", strategy = " org.hibernate.id.SequenceGenerator ", parameters = { @Parameter(name = "sequence", value = "ARCHIVE_SEQ") }) private Integer nid; /**your code**
Recent posts