-->
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: query by Criteria and set of composite-elements not working
PostPosted: Fri Jul 23, 2004 6:42 pm 
Newbie

Joined: Tue Jul 13, 2004 9:55 pm
Posts: 7
Location: Tucson, AZ
Relevant platform details:
Hibernate 2.1.2
Spring 1.0.1
jdk1.4.2
MySQL 4.0.16-standard


Hi all. I'm trying to rewite an HQL query for use in a search page and I want to use the query by Criteria API. However, I am having problems querying on a property of a set element that is a composite-element. It worked just fine in HQL but it is not working in the Criteria API.

The old HQL query that worked fine was this:
Code:
select page from org.tolweb.hibernate.MappedAccessoryPage as page  join page.contributors as contributors  where  contributors.contributorId = :contributor_id


The query by Criteria code is this:
Code:
Criteria criteria = session.createCriteria(MappedAccessoryPage.class);
criteria.createAlias("contributors", "contributors");
criteria.add(Expression.eq("contributors.contributorId", new Integer(contr.getId()));


When I run that Criteria code I get this exception:

Code:
net.sf.hibernate.MappingException: collection was not an association: org.tolweb.hibernate.MappedAccessoryPage.contributorsnet.sf.hibernate.MappingException: collection was not an association: org.tolweb.hibernate.MappedAccessoryPage.contributors at net.sf.hibernate.type.PersistentCollectionType.getAssociatedClass(PersistentCollectionType.java:213) at net.sf.hibernate.impl.CriteriaImpl.getClassForPath(CriteriaImpl.java:328) at net.sf.hibernate.impl.CriteriaImpl.createAlias(CriteriaImpl.java:285) at net.sf.hibernate.impl.CriteriaImpl.createAlias(CriteriaImpl.java:261) at


Is it not possible to do this sort of querying in the Query by Criteria API or did I screw something else up?

Thanks for your time, and here is the mapping doc:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
    <class
        name="org.tolweb.hibernate.MappedAccessoryPage"
        table="ACCESSORY_PAGES"
        dynamic-update="false"
        dynamic-insert="false"
    >
        <id
            name="accessoryPageId"
            column="id"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="native">
            </generator>
        </id>

        <set
            name="contributors"
            table="ACC_PAGE_CONTRIBUTORS"
            lazy="false"
            inverse="false"
            cascade="none"
            sort="natural"
            order-by="page_order asc"
        >

              <key
                  column="page_id"
              >
              </key>

              <composite-element
                  class="org.tolweb.treegrow.page.AccessoryPageContributor"
              >

        <property
            name="order"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="page_order"
        />

        <property
            name="contributorId"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="contributor_id"
        />

        <property
            name="isAuthor"
            type="boolean"
            update="true"
            insert="true"
            access="property"
            column="is_author"
        />

        <property
            name="isContact"
            type="boolean"
            update="true"
            insert="true"
            access="property"
            column="is_contact"
        />

        <property
            name="isCopyOwner"
            type="boolean"
            update="true"
            insert="true"
            access="property"
            column="is_copy_owner"
        />

              </composite-element>

        </set>

        <property
            name="submittedContributorId"
            type="java.lang.Long"
            update="true"
            insert="true"
            access="property"
            column="submitted_contributor_id"
        />

        <property
            name="submissionDate"
            type="java.util.Date"
            update="true"
            insert="true"
            access="property"
            column="submission_date"
        />

        <property
            name="isSubmitted"
            type="boolean"
            update="true"
            insert="true"
            access="property"
            column="is_submitted"
        />

        <property
            name="isTreehouse"
            type="boolean"
            update="true"
            insert="true"
            access="property"
            column="is_treehouse"
        />

        <property
            name="menu"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="menu"
        />

        <property
            name="pageTitle"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="page_title"
        />

        <property
            name="copyright"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="page_copyrightholder"
        />

        <property
            name="copyrightYear"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="page_copyrightdate"
        />

        <property
            name="text"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="main_text"
        />

        <property
            name="references"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="refs"
        />

        <property
            name="status"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="status"
        />

        <property
            name="useContent"
            type="boolean"
            update="true"
            insert="true"
            access="property"
            column="use_content"
        />

        <set
            name="internetLinks"
            table="InternetLinks"
            lazy="false"
            inverse="false"
            cascade="none"
            sort="natural"
            order-by="link_order asc"
        >

              <key
                  column="acc_page_id"
              >
              </key>

              <composite-element
                  class="org.tolweb.treegrow.page.InternetLink"
              >
        <property
            name="order"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="link_order"
        />

        <property
            name="comments"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="comments"
        />

        <property
            name="siteName"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="siteName"
        />

        <property
            name="url"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="url"
        />

              </composite-element>

        </set>

        <set
            name="nodesSet"
            table="Acc_Pages_To_Nodes"
            lazy="false"
            inverse="false"
            cascade="none"
            sort="unsorted"
        >

              <key
                  column="acc_page_id"
              >
              </key>

              <many-to-many
                  class="org.tolweb.hibernate.MappedNode"
                  column="node_id"
                  outer-join="auto"
               />

        </set>

        <property
            name="contributorId"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="contributor_id"
        />

        <property
            name="usePermission"
            type="byte"
            update="true"
            insert="true"
            access="property"
            column="use_permission"
        />
        <property
            name="acknowledgements"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="acknowledgements"
        />
        <property
            name="notes"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="notes"
        />
    </class>
</hibernate-mapping>

_________________
Danny Mandel <dmandel at nospam dot tolweb dot org>
Lead Programmer, Tree of Life Project
http://tolweb.org


Top
 Profile  
 
 Post subject: query by Criteria and set of composite-elements not working
PostPosted: Mon Mar 07, 2005 7:05 pm 
Newbie

Joined: Mon Mar 07, 2005 6:55 pm
Posts: 2
¿Does anyone knows the solution to this problem? I am having a similar problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 2:06 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 3:48 am
Posts: 23
Oh,

I'm having the same problem.

http://forum.hibernate.org/viewtopic.php?t=943792&highlight=compositeelement

Anyone know the solution?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 2:06 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 3:48 am
Posts: 23
Oh,

I'm having the same problem.

http://forum.hibernate.org/viewtopic.php?t=943792&highlight=compositeelement

Anyone know the solution?


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.