-->
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: Simple Map Question
PostPosted: Fri Jul 21, 2006 10:49 am 
Beginner
Beginner

Joined: Thu Dec 15, 2005 12:02 pm
Posts: 23
Hello,
I have two tables both are entity (both have a primary key).
cat and format

I would like to query cat and bring back all format_name where the format_id(s) are equal. This simple query
mysql> select cat.cat_name, cat.cat_id, format.format_name
-> from cat, format
-> where cat.format_id = format.format_id;

Currently I have two separate mappings. I need to create a mapping for this. I do not believe it is a one-to-many or anything where a set is involved, and could use some help in distinguishing my need.

Thanks,
Scott



mysql> describe cat;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| cat_id | int(8) | NO | PRI | 0 | |
| cat_name | varchar(50) | YES | | NULL | |
| format_id | int(8) | YES | MUL | 1 | |
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> describe cat;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| cat_id | int(8) | NO | PRI | 0 | |
| cat_name | varchar(50) | YES | | NULL | |
| format_id | int(8) | YES | MUL | 1 | |
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 11:51 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Set up a relationship. That's exactly what you need. Query a cat, get back all the matching format_ids in a collection in the Cat class. Hibernate will do all the work if you just call a simple load

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject: One-to-one
PostPosted: Fri Jul 21, 2006 1:55 pm 
Beginner
Beginner

Joined: Thu Dec 15, 2005 12:02 pm
Posts: 23
After much investigating, the final answer to my problem was to create a One-to-one association pp220 in the action book.

Thanks for all the replies, this list really delivers results.


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.