Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] multiple access to same db field

Yes, you need to set the studentId when you set the student.  The best way to
do this is to just have your setStudent() set method also set the studentId,
then you do not need to worry about it.



ymajoros wrote:
> 
> 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
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://old.nabble.com/multiple-access-to-same-db-field-tp29171398p29173475.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top