-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate (Many-To-One realtion)
PostPosted: Fri Jan 21, 2011 6:52 am 
Newbie

Joined: Thu Dec 23, 2010 4:51 am
Posts: 3
Location: Atlanta (USA)
Hi buddies!

I have a web application and I have used those frameworks:
Spring
Hibernate
Struts


Until now I had no relationships between tables but I would like to add a Many-To-One relationship in my web application. I'm using annotations and I have found some examples where I could see how implement it and I think that is well implemented.

I have a Category table whose fields are:
Id (Integer)
Name (String)

I have a GreenPoint table whose fields are:
Id (Integer)
City (String)
Location (String)
Adress (String)
etc.

I have a GreenPointHasCategory table (linked table) whose fields are:
id (Integer)
greenpoint_id (it is a FK to GreenPoint id table)
category_id (it is a FK to Category id table)


The question is the following: I have a form where an user can do a search by city or location but I also would like to do a search by category.

I know how I should do it in MySQL:

SELECT DISTINCT p.* FROM greenpoint as p, category as c, greenpoint_has_category as pc WHERE p.id = pc.greenpoint_id AND c.id = pc.category_id AND c.id = 4;
In this case the category selected is the number 4.

But I don't know how can do an SQL sentence from GreenPointDaoHibernate and in this class call to Category and GreenPointHasCategory tables.

I don't know if I have explained me.

Any advice?

Thanks in advance!

If you need some code, just tell me! ;)

-Samuel-
PS: Sorry for my english!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.