-->
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: Avoid duplicate inf
PostPosted: Sat Oct 27, 2007 12:51 pm 
Newbie

Joined: Sat Oct 27, 2007 12:32 pm
Posts: 2
I have two tables with one to many relationship. What can I do in order to avoid duplicate information.

For instance

Categories
Id
Name

Products
Id
IdCategory
Name



What can i do to select information from both tables and also to specify criteria for both tables without retrieving duplicate information???

Im not sure if the only way is with a subquery
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 29, 2007 6:30 am 
Newbie

Joined: Thu Oct 18, 2007 10:38 am
Posts: 7
Try the query:

Code:
Query q = session.createQuery("select cat from Products as prod inner join prod.idCategory");
List<Products> result = q.list();

for (Products p : result) {
  System.out.println(p.getName() + " is in " + p.getIdCategory().getName());


No garantuee for this. The interesting part is the inner join.


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.