-->
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.  [ 5 posts ] 
Author Message
 Post subject: Identifiers and their values?
PostPosted: Fri Apr 11, 2008 6:33 am 
Newbie

Joined: Fri Apr 11, 2008 6:13 am
Posts: 8
Hi,

I have some string data and their corresponding identifiers on the database as below

Code:
id| department
--|------
1 | Math
2 | Physics
3 | Comp.Science
...


And in another table named Student there is a column that stores student's department identifier. I want to hold the id's of the departments on the Student table. When loading a Student row, I want to see names of the departments on the Student object. And when saving the object to the database, I want to see identifier(1,10,3...) of the department on the database. Is there anyway to make this without making the Department as a class?

I read the documents on the website and googled but can't find any samples


Top
 Profile  
 
 Post subject: Re: Identifiers and their values?
PostPosted: Fri Apr 11, 2008 10:02 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
It's very much like a collection of elements which in this case are Strings.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 12, 2008 8:37 am 
Newbie

Joined: Fri Apr 11, 2008 6:13 am
Posts: 8
I think I couldn't explain what the problem is. For example i have a class as below

Code:
public class Student
{
   private int id;
   private String name;
   private String department;
   ...
}


Student's department attribute can be "Math", "Physics", "Computer Science" etc. Just one of them. But in the database I want to hold the department as an integer. For example

Code:
id| name    | department(int)
--|---------|-----------
1 | justin  | 2
2 | george  | 1
3 | michael | 1


When i fetch a Student row from the database, I want to load the Student object's department field with string represantation which stores in another table named Department as below

s.id = 1
s.name = "george"
s.department = "Math" (not 1 or any other integer value)

Is it possible?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 12, 2008 2:19 pm 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
No I don't think so. Your object should have an instance variable Department instead of a String department name.

Code:
public class Student
{
   private int id;
   private String name;
   private Department department;
   ...
}


this would fetch the department to which the student belongs. You cannot have one property here and other in the table as in your example. You can have the entire object if you want. I hope I am right ;)

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 5:46 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
You might be able to use <join ...>. This is useful for situations in which an entity's columns are stored in multiple tables.



Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.