-->
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.  [ 5 posts ] 
Author Message
 Post subject: Criteria API createAlias to a 'map' property type
PostPosted: Mon Feb 16, 2004 6:24 pm 
Newbie

Joined: Mon Feb 16, 2004 2:36 pm
Posts: 12
Hi,

I have a property that is mapped as a 'map' with a String index column and a composite-element. I am trying to use the Criteria API and join onto this mapped column to fetch only rows with a specific mapped index.

How do you use the Query API... ie criteria... to join to a property that is a 'map'???

I can successfully create a string query and use the session.find(squery) to fetch my records.

However, if I try to the API query I am getting the attached error.

The straight query that WORKS:
Code:
String query = "select us " + "from com.esage.agility.domain.UserStory us " + "join us.propertiesMapped prop where prop.valueDomainId = 1 and index(prop) = 'CUSTOM_PROPERTY_235'";

results = HibernateSession.currentSession().find(query);


My attempt at a criteria api based approach. I simplified it a bit:
Code:
results = HibernateSession.currentSession().createCriteria(UserStory.class)
                .createAlias("propertiesMapped", "prop")


Code:
When I execute this criteria I get this error:

net.sf.hibernate.AssertionFailure: not an association
   at net.sf.hibernate.collection.AbstractCollectionPersister.getElementPersister(AbstractCollectionPersister.java:707)
   at net.sf.hibernate.type.PersistentCollectionType.getAssociatedClass(PersistentCollectionType.java:221)
   at net.sf.hibernate.impl.CriteriaImpl.getClassForPath(CriteriaImpl.java:282)
   at net.sf.hibernate.impl.CriteriaImpl.createAlias(CriteriaImpl.java:239)
   at net.sf.hibernate.impl.CriteriaImpl.createAlias(CriteriaImpl.java:215)
   at com.esage.agility.action.ExecuteSearchCriteriaAction.executeSearch(ExecuteSearchCriteriaAction.java:63)
   at com.esage.agility.action.ExecuteSearchCriteriaAction.executeAction(ExecuteSearchCriteriaAction.java:41)
   at com.esage.agility.action.ExtractSearchCriteriaAction.executeSearch(ExtractSearchCriteriaAction.java:55)
   at com.esage.agility.action.ExtractSearchCriteriaAction.executeAction(ExtractSearchCriteriaAction.java:42)
   at com.esage.agility.action.BaseActionSupport.execute(BaseActionSupport.java:77)


And here is the mapping file:(only what I thought would be interesting)

Code:
    <class name="com.esage.agility.domain.Case" table="BASE_CASE" discriminator-value="B">
        <cache usage="read-write"/>


<map name="propertiesMapped" table="PROPERTY_SET" >
    <key column="CASE_ID"/>
    <index column="TYPE" type="string"/>

    <composite-element class="com.esage.agility.domain.propertyset.PropertySetItem">
            <property name="valueLong" column="VALUE_LONG" type="long"/>
            <property name="valueString" column="VALUE_STRING" type="string"/>
            <property name="valueDomainId" column="VALUE_DOMAIN_ID" type="long"/>
    </composite-element>

</map>

        <!--
        <set name="propertiesSet" lazy="true" cascade="all">

            <key column="entity_id"/>
            <one-to-many class="com.opensymphony.module.propertyset.hibernate.PropertySetItem"/>
        </set>
-->
        <many-to-one name="parent" class="com.esage.agility.domain.Case" column="PARENT_CASE_ID"/>
<!--        <many-to-one name="assignedTo" class="com.esage.agility.domain.Person" column="ASSIGNED_TO"/>
-->

        <subclass name="com.esage.agility.domain.UserStory" discriminator-value="U">
        </subclass>
    </class>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 4:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This (querying collections of values) is not currently supported in Criteria API. Use HQL.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 12:42 pm 
Newbie

Joined: Mon Feb 16, 2004 2:36 pm
Posts: 12
Any chance of getting this implemented any time soon.
My code went from cool using the API to ugly using the HQL.

Mike


Top
 Profile  
 
 Post subject: This (querying collections of values) is not currently suppo
PostPosted: Tue Mar 23, 2004 9:54 pm 
Beginner
Beginner

Joined: Tue Mar 23, 2004 8:40 pm
Posts: 22
How about if I work around it with the followings for the collection (the rest would still use Criteria API):

Code:
        Criterion criterion = Expression.sql("exists (select 1 from property_set where {alias}.id = property_set.case_id and property_set.value_string like upper(?))", s, Hibernate.STRING);
        _criteria.add(criterion);



P.S.

Any dynamic way to retrieve the collection table name and key column name ? (via session.getSessionFactory().getClassMetadata ??)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 12:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You can get mapping metadata from the Configuration object.


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