mapping DB tables and classes - newbie question

Let's say i have 3 tables in the DB:

author

cd

track

Every author can be related to many cds, and every cd can be related with many tracks. In the db relations are realized by identifiers. But in the classes should i use references? I mean, should an author have a reference to every cd he made?And indeed should every cd have a reference to its author? And when i do a query to the DB to find an author should i also find every cd related to that author and every track related to the cds? Or can i take the information about cds and track form the DB only when needed?

Maybe it is a banal question but it's a terrible doubt for me and i didn't find any solution in the forum.

[717 byte] By [anjaa] at [2007-10-2 12:39:42]
# 1

> Let's say i have 3 tables in the DB:

> author

> cd

> track

>

> Every author can be related to many cds, and every cd

> can be related with many tracks. In the db relations

> are realized by identifiers. But in the classes

> should i use references? I mean, should an author

> have a reference to every cd he made?

>And indeed

> should every cd have a reference to its author? And

Typically an Author might have a List or Set of CDs. A CD might also have an author field--or List of authors if you're allowing for multiple authors to collaborate on a CD.

Which directions are navigable is entirely dictated by your requirments.

> when i do a query to the DB to find an author should

> i also find every cd related to that author and every

> track related to the cds?

That depends on what you're trying to do, what kind of performance concerns you have.

> Or can i take the

> information about cds and track form the DB only when

> needed?

Yes, you can. How you do it depends on your needs in your particular situation.

> Maybe it is a banal question but it's a terrible

> doubt for me and i didn't find any solution in the

> forum.

No, these are valid design concerns, and something that you always need to ask. It's impossible to provide specific answers here because we don't know details of your requirements.

One thing you might want to look into--though there is a bit of a learning curve--is an ORM tool like Hibernate. You still have to make these decisions, but once you make them, you can implement many of them by simple changes to XML files that configure the mapping between your classes and the DB.

http://www.hibernate.org/

jverda at 2007-7-13 9:43:03 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

> Maybe it is a banal question but it's a terrible

> doubt for me and i didn't find any solution in the

> forum.

It sounds like you know squat about designing software in general, and relational database design in particular. If you would like to remove your terrible doubt, then stop depending upon the "forum" and do some work.

Master_Consultanta at 2007-7-13 9:43:03 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

> > Maybe it is a banal question but it's a terrible

> > doubt for me and i didn't find any solution in the

> > forum.

>

> It sounds like you know squat about designing

> software in general, and relational database design

> in particular. If you would like to remove your

> terrible doubt, then stop depending upon the "forum"

> and do some work.

oh! I'm very sorry I disturbed you with my stupid questions...I really don't think I depend upon the forum, I asked only a few questions. I do work, a lot. I am a student, I studied a lot of theory but i have a little experience and I think this is a good place to get advantage of people's experience. Besides i don't think you even read carefully my question since i have no problem with database design, i have rather problems with classes design. Maybe it was my fault, since english is not my mother language.

anjaa at 2007-7-13 9:43:03 > top of Java-index,Other Topics,Patterns & OO Design...
# 4
i forgot to thank jverd! you were helpful and very kindthanks:)
anjaa at 2007-7-13 9:43:03 > top of Java-index,Other Topics,Patterns & OO Design...
# 5
You're welcome.Good luck! :-)
jverda at 2007-7-13 9:43:03 > top of Java-index,Other Topics,Patterns & OO Design...