Usando uma sequencia customizada no Hibernate Annotations

Para usar uma sequence para cada classe no hibernate, use o seguinte codigo:

......
@Entity
@Table(name="PESSOA")
@SequenceGenerator(name = "SEQ_PESSOA", sequenceName = "SEQ_PESSOA",allocationSize=0,initialValue=1)
public class Pessoa {

@Id
@GeneratedValue(generator="SEQ_PESSOA",strategy=GenerationType.SEQUENCE)
@Column(name="ID_PESSOA")
private Long Id;
......

Simples!

Posted in Java | No Comments »

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.