[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] multiple access to same db field
|
Hi,
For historical reasons, some db fields in our model can be accessed
from multiple fields in an entity class. Some example:
@Entity
public class StudentExam implements Serializable {
[...]
@Column(name = "student_id", insertable = false, updatable = false)
private Long studentId;
@JoinColumns({@JoinColumn(name = "student_id", referencedColumnName
= "id")})
@ManyToOne
private Student student;
[...]
}
My opinion is that following code is broken (will insert ok in db, but
cache could be corrupted):
StudentExam studentExam = new StudentExam();
studentExam.setExam(someExam);
studentExam.setStudent(someStudent);
StudentExam savedStudentExam = entityManager.merge(studentExam);
Instead, I think we should use add this line before the merge:
studentExam.setStudentId(someStudent.getId());
... even if it sounds strange. Otherwise, studentExam.getStudentId()
could be inconsistent, later. Our team cannot agree on this, we need to
be sure. There is too much historical code, so simply removing studentId
from the mapping is not an option :-(
Could someone help me with an opinion, or even some specification
reference?
Thank you,
Yannick Majoros
begin:vcard
fn:Yannick Majoros
n:Majoros;Yannick
org:UCL;SGSI/EPC
adr;quoted-printable:;;place de l'Universit=C3=A9, 1;Louvain-la-Neuve;;1348;Belgique
email;internet:yannick.majoros@xxxxxxxxxxxx
title;quoted-printable:D=C3=A9veloppeur
tel;work:+32 10 47.94.42
tel;cell:+32 498 70.72.13
x-mozilla-html:TRUE
version:2.1
end:vcard