-->
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: Is there an elegant way to handle linking tables
PostPosted: Wed Nov 24, 2010 9:25 pm 
Newbie

Joined: Wed Nov 24, 2010 9:17 pm
Posts: 1
There may already be an answer for this on the forum somewhere because it is a common problem, but apparently I don't know what the right search terms for it would be to find it, so here it goes:

I have a product table, category table, and a product_category table that links the two. What is the best way to pass in a category id and get all the product rows for that category id?

Do I just do something like this:
Code:
List<ProductCategory> productCategories = getHibernateTemplate().find("from product_category where product_t = ? order by category_order", categoryId);
      List<Product> products = new ArrayList<Product>();
      for (ProductCategory productCategory : productCategories)
      {
         products.add(productCategory.getProduct());
      }
      return products;



Is there a better way?


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.