Estaba enfrentando este problema, también.
La tabla de destino es una tabla de relaciones, conectando dos identificadores de diferentes tablas. Tengo una restricción ÚNICA en la combinación de valores, reemplazando el PK. Al actualizar uno de los valores de una tupla, se produjo este error.
Esta es la forma en la mesa se ve como (MySQL):
CREATE TABLE my_relation_table (
mrt_left_id BIGINT NOT NULL,
mrt_right_id BIGINT NOT NULL,
UNIQUE KEY uix_my_relation_table (mrt_left_id, mrt_right_id),
FOREIGN KEY (mrt_left_id)
REFERENCES left_table(lef_id),
FOREIGN KEY (mrt_right_id)
REFERENCES right_table(rig_id)
);
la clase de entidad para la entidad RelationWithUnique
se ve básicamente como esto:
@Entity
@IdClass(RelationWithUnique.class)
@Table(name = "my_relation_table")
public class RelationWithUnique implements Serializable {
...
@Id
@ManyToOne
@JoinColumn(name = "mrt_left_id", referencedColumnName = "left_table.lef_id")
private LeftTableEntity leftId;
@Id
@ManyToOne
@JoinColumn(name = "mrt_right_id", referencedColumnName = "right_table.rig_id")
private RightTableEntity rightId;
...
me fijo por
// usually, we need to detach the object as we are updating the PK
// (rightId being part of the UNIQUE constraint) => PK
// but this would produce a duplicate entry,
// therefore, we simply delete the old tuple and add the new one
final RelationWithUnique newRelation = new RelationWithUnique();
newRelation.setLeftId(oldRelation.getLeftId());
newRelation.setRightId(rightId); // here, the value is updated actually
entityManager.remove(oldRelation);
entityManager.persist(newRelation);
Muchas gracias por la pista de la PK, simplemente me lo perdí.
¿Su tabla de usuario debe cambiar su valor? ¿Qué valor? La tabla de usuario presumiblemente contiene varias filas con varios valores cada ... – meriton