-->
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: Arbitrary Joins using HQL/Critiera
PostPosted: Thu Apr 14, 2005 5:48 am 
Beginner
Beginner

Joined: Tue Sep 09, 2003 9:11 pm
Posts: 32
I know with 2.x I can perform have an arbitrary join in hql - but not using the Criteria API. With 3.x is it possible to perform arbitrary joins using the Criteria API, or are there plans to add this support?

The main reason I ask is all of our "search" forms use the criteria api to find objects. Criterias are easier to create using Example and add in associations as needed when compared to generating similar HQL.

However, I have run into a requirement that requires an arbitrary join and I'm hoping to continue to use the Criteria API.

I've gotten a sample query to work in HQL (using mysql). I can build the rest of the search lookup functionality if that's the only way. Just thought I would ask first since I didn't find anything in the docs about the Criteria API supporting this type of query.

As way of example here is the HQL. I'm trying to create something similar using the Criteria API.

Code:
Query q = s.createQuery(
            "from com.entity.Person as person " +
            "   join person.organization as org, " +
            "   com.entity.Organization hier " +
            "where hier.name like 'schawk%' " +
            "   and org.hierarchy like concat(hier.hierarchy, '%')"
      );


The basic mapping is:
Code:
<class name="com.entity.Party" table="party" lazy="true" discriminator-value="X0">
       <id name="partyID" type="long" unsaved-value="0" >
          <generator class="identity"/>
       </id>
          <subclass name="com.entity.Person" discriminator-value="P" lazy="true">
             <many-to-one name="organization" class="com.entity.Organization"
                 column="organization" cascade="save-update"/>
          </subclass>
          <subclass name="com.entity.Organization" discriminator-value="O" lazy="true">
             <many-to-one name="parent" class="com.entity.Organization" cascade="save-update"
               column="organization"/>
             <property name="hierarchy" type="string" length="210" />
       </subclass>
    </class>

The hierarchy property is a concatenation of the parent's ids.

Thanks in advance,
Chris....


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.