-->
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.  [ 12 posts ] 
Author Message
 Post subject: Query by Mapped Composite Element - illegally dereferenced
PostPosted: Mon Feb 16, 2004 2:39 pm 
Newbie

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

I am trying to create a query based on the values of a map containing composite-elements. I have a Map property called propertiesMapped. The elements withing this map are mapped as composite-elements. I want to join only based on a property of the composite-element, in my example the property 'valueLong'.

If I execute the query as attached, I get the attached error message.

What am I doing wrong.

Also note that I really want to make this work using the query api, but I have simplified my example here.

Thanks in advance.

String query =
"from bean in class com.esage.agility.domain.UserStory where bean.propertiesMapped['KEY1'].valueLong = 2";
results = HibernateSession.currentSession().find(query);


<class name="com.esage.agility.domain.Case" table="BASE_CASE" >
...
<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"/>
</composite-element>

</map>
...

</class>


With the following stack trace:
net.sf.hibernate.QueryException: illegally dereferenced collection element [from bean in class com.esage.agility.domain.UserStory where bean.propertiesMapped['CUSTOM_PROPERTY_235'].valueLong = 2]
at net.sf.hibernate.hql.WhereParser.getElementName(WhereParser.java:173)
at net.sf.hibernate.hql.WhereParser.continuePathExpression(WhereParser.java:453)
at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:197)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:293)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1493)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1464)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1454)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1446)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 2:48 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Which version of Hibernate ?
composite-element can be queried since 2.1

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 2:50 pm 
Newbie

Joined: Mon Feb 16, 2004 2:36 pm
Posts: 12
The ver is 2.1.1


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 2:57 pm 
Newbie

Joined: Mon Feb 16, 2004 2:36 pm
Posts: 12
Also,
I tried doing it another way and I got the same 'dereferenced' error message.

String query = "from com.esage.agility.domain.UserStory us where index(us.propertiesMapped.indices) = 'KEY1' and us.propertiesMapped.valueLong = 2";

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

Error Message:
Could not execute hibernate query. Chained Message: dereferenced: userstory0_.propertiesMapped.indices.index [from com.esage.agility.domain.UserStory us where index(us.propertiesMapped.indices) = 'KEY1' and us.propertiesMapped.valueLong = 2].


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 3:41 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
<class name="com.esage.agility.domain.Case

is different from the requested class com.esage.agility.domain.UserStory

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 3:53 pm 
Newbie

Joined: Mon Feb 16, 2004 2:36 pm
Posts: 12
emmanuel wrote:
Code:
<class name="com.esage.agility.domain.Case

is different from the requested class com.esage.agility.domain.UserStory


The UserStory is actually a Hib. mapped sub-class. I just trimmed that section out of the mapping I sent.

I just tried changing the query to use just Case... same results


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 4:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I'm not familiar with these kind of queries.

Try
Code:
from com.esage.agility.domain.UserStory bean where bean.propertiesMapped['KEY1'] = :item

And item is PropertySetItem having valueLong to 2.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 4:36 pm 
Newbie

Joined: Mon Feb 16, 2004 2:36 pm
Posts: 12
I really appreciate the help.
But, that last pointer did not help. I have now simplified the query to just the simplest possible. I am now just trying to get the UserStories where there is a property mapped by KEY1.

Here is the method that I 'expect' to be called on the UserStory class. There is a corresponding setter as well.

The new query is attached as well


I did find this forum topic that was close to my issue.

http://forum.hibernate.org/viewtopic.ph ... referenced

Code:
String query =
                    "from com.esage.agility.domain.UserStory us where index(us.propertiesMapped.indices) in 'KEY1 ";

vs

Code:
select req
from QuoteRequest req
join req.coverSheet.actions action
where action.parameter.stringValue = '123456'
and index(action) = 'Provider_In'


I had to put the indices on the end of my propertyMapped reference. Otherwise Hib was complaining that an elements or indices was expected after the index.


Code:
public Map getPropertiesMapped() {
        return propertiesMapped;
}





Here is the error... same as before.
net.sf.hibernate.QueryException: dereferenced: userstory0_.propertiesMapped.indices.index [from com.esage.agility.domain.UserStory us where index(us.propertiesMapped.indices) in 'CUSTOM_PROPERTY_236' ]
at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:140)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 4:37 pm 
Newbie

Joined: Mon Feb 16, 2004 2:36 pm
Posts: 12
For completeness here is the hbm mapping file

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="com.esage.agility.domain.Case" table="BASE_CASE" discriminator-value="B">
        <cache usage="read-write"/>
        <id column="BASE_CASE_ID" type="long" name="id" unsaved-value="null">
            <generator class="identity"/>
        </id>
        <discriminator column="class" type="string"/>
<!--        <timestamp column="LAST_UPDATED_TIMESTAMP" name="lastUpdatedTimestamp"/>
-->
        <property name="description" column="description" type="string"/>
        <property name="title" column="TITLE" type="string"/>
        <property name="createdTimestamp" column="created_timestamp" type="date"/>
        <property name="lastUpdatedTimestamp" column="LAST_UPDATED_TIMESTAMP" type="date"/>

        <many-to-one name="status" class="com.esage.agility.domain.DomainValue" column="STATUS"/>
        <many-to-one name="caseType" class="com.esage.agility.domain.CaseType" column="CASE_TYPE"/>
        <many-to-one name="priority" class="com.esage.agility.domain.DomainValue" column="PRIORITY"/>
        <many-to-one name="targetIteration" class="com.esage.agility.domain.DomainValue" column="TARGET_ITERATION"/>
        <many-to-one name="assignedTo" class="com.esage.agility.domain.Person" column="ASSIGNED_TO"/>
        <many-to-one name="createdBy" class="com.esage.agility.domain.Person" column="CREATED_BY"/>
        <many-to-one name="lastUpdatedByUser" class="com.esage.agility.domain.Person" column="LAST_UPDATED_BY_USER_ID"/>
        <many-to-one name="project" class="com.esage.agility.domain.Project" column="PROJECT"/>

        <!--
        <property name="priorityId" column="PRIORITY" type="long"/>
        <property name="assignedToId" column="ASSIGNED_TO" type="long"/>
        -->
        <set name="dependents" lazy="true" cascade="all">
            <key column="PARENT_CASE_ID"/>
            <one-to-many class="com.esage.agility.domain.Case"/>
        </set>

        <set name="attachments" lazy="true" cascade="all">
            <key column="CASE_ID"/>
            <one-to-many class="com.esage.agility.domain.Document"/>
        </set>

        <set name="estimates" lazy="true" cascade="all"  inverse="true">
            <key column="CASE_ID"/>
            <one-to-many class="com.esage.agility.domain.WorkItem"/>
        </set>

        <set name="history" lazy="true" cascade="all">
            <key column="CASE_ID"/>
            <one-to-many class="com.esage.agility.domain.CaseHistory"/>
        </set>

        <set name="comments" lazy="true" cascade="all" inverse="true">
            <key column="CASE_ID"/>
            <one-to-many class="com.esage.agility.domain.Comment"/>
        </set>

        <set name="inboundLinks" lazy="true" cascade="all" inverse="true">
            <key column="INBOUND_CASE_ID"/>
            <one-to-many class="com.esage.agility.domain.Link"/>
        </set>

        <set name="outboundLinks" lazy="true" cascade="all" inverse="true">
            <key column="OUTBOUND_CASE_ID"/>
            <one-to-many class="com.esage.agility.domain.Link"/>
        </set>


<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>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 4:42 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This doesn't work ?
Code:
select us
from com.esage.agility.domain.UserStory us
join us.propertiesMapped prop
where prop.valueLong = 2
and index(prop) = 'KEY1'

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 4:50 pm 
Newbie

Joined: Mon Feb 16, 2004 2:36 pm
Posts: 12
BINGO!
Thanks Emmanuel!!
I did not have the JOIN.
Code:
join us.propertiesMapped prop

I am not clear on why this join is needed? Isn't this column already going to be join by Hibernate since its in my mapping?

Also, is it possible to make this into a query using the API?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 3:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
botah wrote:
I am not clear on why this join is needed? Isn't this column already going to be join by Hibernate since its in my mapping?

Also, is it possible to make this into a query using the API?

Being in the mapping means Hibernate know how to make the join. The HQL is on top of SQL and let you do what you want (compared to .load()).

I don't know well the Criteria API.

_________________
Emmanuel


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