Hello,
I am developing a system in an existing database and I have difficulty using a sequence of bank within a Hibernate Embeddable mapping.
Whenever I try to insert a new record value of idPessoa (PES_ID) is zero, it does not trigger the sequence.
Does anyone know how to solve this problem?
Class Main table:Code:
@Entity
@Table(name = "PES_PESSOA" )
public class Pessoa implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private PessoaPK id;
@Column(name = "PES_NOME" )
private String nome;
@Column(name = "PES_LOGRADOURO" )
private String logradouro;
@Column(name = "PES_BAIRRO" )
private String bairro;
....
}
Class Embeddable with Sequence:Code:
@Embeddable
public class PessoaPK implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "EMP_ID" )
private long idEmpresa;
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenciaPessoa" )
@SequenceGenerator(name = "sequenciaPessoa", sequenceName = "S_PES_PESSOA", allocationSize = 1 )
@Column(name = "PES_ID" )
private long idPessoa;
...
}
Grateful!