-->
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.  [ 3 posts ] 
Author Message
 Post subject: Association-I want to keep also in the object the parent ID
PostPosted: Sun Apr 09, 2006 10:40 am 
Newbie

Joined: Thu Mar 09, 2006 5:48 am
Posts: 10
Hibernate version:
3.1 (ejb 3)

Name and version of the database you are using:
MYSQL

Hi All,
My question is: I have association mapping of one to many
i.e - teacher (one) and students (many)
the teacher has collection of her students
and the student keep refrerence to its parent (his teacher)
Code:
public class Student  {

   private int id;
   private transient Teacher device;
...
}


now, my question is how can I have a member/method which will return the teachID in the student class in the GUI side?.

(I need it because when my system is client-server and I marked the parent as transient in the student class because I don't want the the serialized process will bring each time all the object graph but still I want to know the teacher ID of a specific student in the client side).


Top
 Profile  
 
 Post subject: One solution that I found is to use @PostLoad
PostPosted: Sun Apr 09, 2006 10:54 am 
Newbie

Joined: Thu Mar 09, 2006 5:48 am
Posts: 10
in the student class I add the following methods
Code:

private int teacherID;

public int getTeacherID() {
   return teacherID;
}

public void setTeacherID(int _teacherID) {
   teacherID=_teacherID;
}

@PostLoad
private void postLoad() {
   setTeacherID(getTeacher().getID());
}


is there a better solution?

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 09, 2006 12:40 pm 
Newbie

Joined: Wed Nov 30, 2005 4:13 pm
Posts: 12
to me it looks like source of future troubles
someone can call setTeacherID(x) where x!= getTeacher().getID()

can't you do this:
public void setTeacher(Teacher teacher) {
this.teacher = teacher;
this.teacherId = teacher.getId();
}

and make TeacherID property read-only?


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

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.