-->
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: Hibernate annotation: mapping query
PostPosted: Tue Sep 20, 2011 1:13 am 
Newbie

Joined: Tue Sep 20, 2011 1:03 am
Posts: 2
Hi,

We are using spring and hibernate in our project and I am new to it.
I know how to map java fields to db colums.
But here is some different requirement , I have to choose one String from drop down box and instead of saving it directly in db;have to save it's lookup id(interger) in main table. Look up id and corresponding string are in different table(look up table).
Can it be possible.Please guide me in this.

Thank You.


Top
 Profile  
 
 Post subject: Re: Hibernate annotation: mapping query
PostPosted: Wed Sep 21, 2011 3:15 am 
Newbie

Joined: Mon Sep 19, 2011 11:16 am
Posts: 2
This is more of a html question than hibernate.
First you query the database for the string/id combinations. These you use to populate the selectbox, using the string as display value and the id as value.
How to do this is dependent on the framework you use, but should result in somethnig like this in your page:
Code:
<select id="form-element-id">
  <option value="121">Volvo</option>
  <option value="243">Saab</option>
  <option value="32">Mercedes</option>
  <option value="373">Audi</option>
</select>


When the form is submitted the selected value (id of the string) is available in the form-element-id variable.


Top
 Profile  
 
 Post subject: Re: Hibernate annotation: mapping query
PostPosted: Thu Sep 22, 2011 12:27 am 
Newbie

Joined: Tue Sep 20, 2011 1:03 am
Posts: 2
Hello tammingaj,

Thanks for help.
Yeah you are correct this is more of a HTML question rather than any framework specific but one doubt in mind.When we save id in main table and during updation it will retrieve id instead of original name.That will not be of any use. How can we display name instead of id during update.


Thank you.


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.