-->
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.  [ 2 posts ] 
Author Message
 Post subject: [Beginner] Howtoput my objects in a database
PostPosted: Sat May 03, 2008 9:07 am 
Newbie

Joined: Tue Apr 29, 2008 5:49 pm
Posts: 3
I have a "database design" problem.

I want to store article and keywords to this articles.
This is a "n to m" relationship.

I thought I can do this by putting the articles in a table, the keywords in a second and the realtionship information in a third.

T_Article:
ID | Name | Author | ...

T_Keyword:
ID | Keyword | ...

T_Rel_Article_Keyword:
ID_Article | ID_Keyword


That's a nice normalization and everythings seems fine - BUT ...

when I want to query all articles with the keyword "A" I first have to get the ID from T_Keyword.
Than I have to use this ID to find all Article-IDs to this Keyword ID in T_Rel_Article_Keyword and
than I can query the Articles in T_Article.

I can optimize this by using a view. Ok. But, I also whant to have the Information, what other keywords are related to the Article I've now queried.

I have to make again a query to T_Rel_Article_Keyword and then to T_Keyword to get this information. For each article.

This is bad.

Is there a better way to do this?

I'm working with java objects of course. So the best way would be a object database to store those objects in.
But I dont know where I can get one, an how to use and administrate such databases.

Or was it the wrong way to specify the DB structure manualy? Should I just put my objects with hibernate in a DB and let hibernate decide how to store it(is this possible?)?
How should I start?

(This is of course just a part of my "object zoo". The center of it all is a "information bundle" holding several smaller beans (like article, keyword, ...).
I just whant to get them all stored.
Atm I have serialized them and load them all on startup into a hashtable. This seams not to be a long term solution to me.)


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 03, 2008 1:04 pm 
Beginner
Beginner

Joined: Fri Apr 11, 2008 1:48 am
Posts: 36
Your solution as described above is absolutly correct. There is no other way to describe a many-to-many relation in the database.

You don't even need an OO Database (by the way: DB4O seems to be really fast and easy to handle). All you need is Hibernate: You will get a mapping of the database in java objects. In that mapped class (entity), you would have a list of all other tables in relation to that.

For example:

class T_Article {
List<Keyword> keywords;
}

So you don't have really to worry about complicated sql statements. Criteria Queries will do all joins for you.


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