-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Sequence generator doesnt work when saveorupdate or merge.
PostPosted: Wed Oct 31, 2012 5:03 am 
Newbie

Joined: Wed Oct 31, 2012 5:00 am
Posts: 1
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!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.