1
Good Afternoon, In an application I am working on we have a table called tb_perfilparametrovalorpdv, following the mapping
@Data
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name = "tb_perfilparametrovalorpdv")
@SequenceGenerator(name = "gen_perfilparametrovalorpdv", sequenceName = "gen_perfilparametrovalorpdv", allocationSize = 1)
public class PerfilParametroValorPDV implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id_perfilparametrovalorpdv", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "gen_perfilparametrovalorpdv")
private Long id;
@Column(name = "tx_descricao", nullable = false)
private String descricao;
@Column(name = "dt_cadastro", nullable = false, updatable = false)
@Temporal(TemporalType.TIMESTAMP)
@CreationTimestamp
private Date dataCadastro;
@Column(name = "dt_manutencao", nullable = true)
@Temporal(TemporalType.TIMESTAMP)
@UpdateTimestamp
private Date dataManutencao;
@Column(name = "nr_sincronizacaoversao", nullable = true)
private Long sincronizacaoVersao;
@Column(name = "dt_exclusao", nullable = true)
@Temporal(TemporalType.TIMESTAMP)
private Date dataExclusao;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "parametroValorPDV", fetch = FetchType.LAZY)
private List<ParametroValorPDV> parametroValorPDVs = new ArrayList<>();
@OneToMany(mappedBy = "parametroValorPDV", fetch = FetchType.LAZY)
private List<VinculoPerfilPDV> vinculoPerfilPDV = new ArrayList<>();
}
We have two applications running in separate databases, where we call one Multi and the other Terminal. Since in Multi we create the records and use Quence, and in the terminal we only synchronize the records. We pass the information from the Multi to the Terminal through a REST API, including passing the id generated by the Multi Quence, but when trying to make the persistence in the terminal by the code
@Override
@Transactional(rollbackFor = Exception.class)
public void sincronizarCarga(List<PerfilParametroValorPDVDTO> listDadosRemoto) throws Exception {
if (!ListUtil.isNullOrEmpty(listDadosRemoto)) {
List<PerfilParametroValorPDV> perfis = modelMapper.map(listDadosRemoto,
TypeToken.getParameterized(List.class, PerfilParametroValorPDV.class).getType());
perfis.forEach(perfilParametroValorPDVRepository::save);
}
}
Hibernate ignores the id passed by DTO and tries to generate a new one. Is there any way to make Hibernate ignore Sequence when receiving an id?