-->
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.  [ 4 posts ] 
Author Message
 Post subject: Criteria Framework Joins
PostPosted: Tue Mar 25, 2008 2:14 pm 
Newbie

Joined: Mon Jul 03, 2006 12:59 pm
Posts: 6
Hi,

General Question. Is it possible to join two tables when there is no mapping association between them?

When there is an association I know you can use 'createAlias' to cause a join to occur. There are some other ways too...

I don't want a subselect or a correlated subquery either, I want an actual join to occur.

Many thanks to anyone can point me in the direction of a relevant doc or api.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 5:21 pm 
Newbie

Joined: Wed Mar 26, 2008 2:34 pm
Posts: 2
Location: Omaha, NE
Hi - yes it is possible but I wasn't able to accomplish it using a Criteria query. Here is an example, hope it helps

Code:
    public List<tableAObject> getValuesBySomeIdList(List<Long> someOtherIdList) {
       List<tableAObject> list = Collections.emptyList();
       
       StringBuffer query = new StringBuffer("select tableA ");
       query.append("from tableAObject tableA, tableBObject tableB ");
       query.append("where tableA.id = tableB.id ");
       query.append("and tableA.someOtherNumVal in (:listParameter)" );
       
       list = getSession().createQuery(query.toString())
          .setParameterList("listParameter, someOtherIdList).list();
       
       return list;
    }

_________________
Thank you,
nedevgrl


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 6:00 pm 
Newbie

Joined: Mon Jul 03, 2006 12:59 pm
Posts: 6
Hi,

Thanks for the response, but unfortunately I'm stuck with the criteria framework for the time being :)

Using this API:

http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Criteria.html#createAlias(java.lang.String,%20java.lang.String,%20int)

it is easy to join entities that have an association, but for two entities whose HBM files do not have properties that point to one other I don't think there is a way.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 6:03 pm 
Newbie

Joined: Mon Jul 03, 2006 12:59 pm
Posts: 6
Also,

This thread:

http://forum.hibernate.org/viewtopic.php?t=969293&highlight=&sid=aa6663d374c0f1dc85971f7d85f69a73

asks the same thing but the only solution suggested is more of the 'subquery' approach.


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