-->
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.  [ 9 posts ] 
Author Message
 Post subject: Hibernate + Struts + Many-to-One question!!
PostPosted: Tue Aug 23, 2005 8:48 am 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
Hello,

i'm trying to do the following. But i have no clue how to handle this.

Lets say you've got Employees and Jobs. An Employee has one job, a job has many employees.

If you want to add an employee, first you've got to choose the job you are about to assign... and keep track of this choice. But, if you are using Many-to-one hibernate relationship, you've got to keep somewhere the object Job, and then, when you save the Employee, take it from somewhere.

The same applies to... when you load an Employee for modification, if you don't keep the Job somewhere and then restore it, you end up loosing it... but you can't put an entire object in a hidden form field.

How would you solve this ???????. Store the 'last-seen-job' in a session variable, both, when you add an employee, or when you load it for update, or there is some easier way ??

THANK YOU!!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 8:59 am 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
It would seem that you still have 2 seconds of work to do yet in this thread: http://forum.hibernate.org/viewtopic.php?t=946585

Then we can move on to your next question!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 9:02 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Maybe im missing ur question, but this sounds like a UI Issue. you could have a drop down of the jobs from a JOBS table and display it when you add/modify the employee.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 9:12 am 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
jdl wrote:
It would seem that you still have 2 seconds of work to do yet in this thread: http://forum.hibernate.org/viewtopic.php?t=946585

Then we can move on to your next question!


Sorry... but i don't get what you mean... :S

I've checked my last post and i've noticed i didn't rate Steven reply, if you meant that, i'm deeply sorry, i didn't even realize of that jdl..!!!


The problem i've got with a simple drop-down menu, is that... in the Employee class, i've got a reference to the Job like this:

private Job j;

and with a simple drop-down, i can't pass a Job property... just the JobID i guess :S


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 9:16 am 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
I'm deeply sorry... truly, i wasn't aware of the rating stuff. I've rated ALL the posts on my list.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 9:18 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Once you get the JobID from ur drop down list, figure out the job using a
session.load(<JobID>, Job.class) to get the Job object and assign it to ur Employee - Job mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 9:22 am 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
That's a good idea. But... i was thinking, wouldn't it be an un-needed query ??. I mean, you've already got the ID you should set to the class.. i actually don't need to re-load the object from the DB... except for Hibernate, that needs the 'real' object instead of the key.

But... that way it can work perfect. I'll give it a shot!!. Thank you :D


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 9:35 am 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
No, load() only creates a proxy. It doesn't execute a query unless you access its non-id properties, which makes it useful for establishing associations without doing a query.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 9:42 am 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
Thank you Nebob!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.