Hi all. My problem is when saveOrUpdate is not getting the right sequence number.
Theses are my entities:
Factura.java
//bi-directional many-to-one association to FacturaConcepto @OneToMany(mappedBy="factura", cascade={CascadeType.ALL}, fetch=FetchType.LAZY) @org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE}) private List<FacturaConcepto> facturaConceptos;
FacturaConcepto.java
@Id @SequenceGenerator(name = "concepto_secuencia", sequenceName = "ID_CONCEPTO_SEC") @GeneratedValue(strategy=GenerationType.AUTO, generator = "concepto_secuencia") @Column(name="ID_CONCEPTO", unique=true, nullable=false, precision=22) private long idConcepto;
//bi-directional many-to-one association to FacturaConcepto @OneToMany(mappedBy="factura", cascade={CascadeType.PERSIST}, fetch=FetchType.LAZY) @org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE}) private List<FacturaConcepto> facturaConceptos;
//bi-directional many-to-one association to FacturaHonorario @OneToMany(mappedBy="facturaConcepto", cascade={CascadeType.ALL}, fetch=FetchType.LAZY) @org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE}) private List<FacturaHonorario> facturaHonorarios;
FacturaHonorario.java
@Id @SequenceGenerator(name = "honorario_secuencia", sequenceName = "ID_HONORARIO_SEQ") @GeneratedValue(strategy=GenerationType.AUTO, generator = "honorario_secuencia") @Column(name="ID_HONORARIO", unique=true, nullable=false, precision=22) private long idHonorario;
//bi-directional many-to-one association to FacturaConcepto @ManyToOne @JoinColumn(name="ID_CONCEPTO", referencedColumnName="ID_CONCEPTO") private FacturaConcepto facturaConcepto;
As you can see, factura has many facturaConcepto, and facturaConcepto has many facturaHonorario.
I have an object factura, with two facturaConcepto and one of these with more than one object facturaHonorario.
In my dao when saveOrUpdate is done The error is "a different object with the same identifier value was already associated with the session". Its happen because in the first facturaConcepto object, the first facturaHonorario has as id a sequence number from dual, but the second one as id has '1'. in the second facturaConcepto object happend exactly the same. The first facturaHonorario object has a sequence number from dual as id, but the second one has '1'. So the sequence generator is not working properly.
If I try merge instead of saveOrUpdate it doesnt fail but when save the second facturaHonorario from the second facturaConcepto smash the second facturaHonorario from the first facturaConcepto.
I suppose all come from entities relationship :s
thanks all!!
|