-->
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: Querying two classes with the result of one
PostPosted: Mon Aug 13, 2007 9:13 pm 
Beginner
Beginner

Joined: Sun Aug 12, 2007 11:22 am
Posts: 44
Location: Sweden
I have this HQL query

Code:
select item, translation  from Item item,  ItemTranslation translation
where item.id = translation.item.id


This works fine and I get both the Item class and the ItemTranslation class.


In my annotation mapping the Item class is not aware of the ItemTranslation class. The ItemTranslation class is howerver aware of the Item class.

This is because I like to separate the translation from the item. The ItemTranslation class must check Language, Store etc. When this query is executed I get a collection of objects.

Code:
Query q = session.createQuery("from item, translation  from Item item,  ItemTranslation translation
where item.id = translation.item.id");

Iterator pairs = q.list().iterator();

while ( pairs.hasNext() ) {
  Object[] pair = (Object[]) pairs.next();
  Item item = (Item) pair[0];
  ItemTranslation translation  = (ItemTranslation) pair[1];
}


The only thing I want from the ItemTranslation class is name and description.
My question is if I can get only the Item class with the ItemTranslation name and description. The Item class has a name and description field that is marked transient.

I want a Item class with it's name and description populated with ItemTranslation name and description. Is this possible?


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.