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>