-->
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.  [ 3 posts ] 
Author Message
 Post subject: Is it now possible to query composite-elements?
PostPosted: Mon Aug 08, 2005 3:19 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 7:53 am
Posts: 32
Location: Madrid - Spain
Hi, I know this problem is not new at all, but after a good search throughout the forum, I have no found evidence of how the current state of querying composite-elements is. The most important threads I've found about this are:

http://forum.hibernate.org/viewtopic.ph ... ent+filter

and

http://forum.hibernate.org/viewtopic.ph ... ent+filter

However, I still wonder if it is possible to query this type of objects by means of createFilter( Object colleciton, String query ).

I my case I have users who have attributes both connected together by a user_attribute_value composite-element in the user side. So when I do:

Code:
user.getUserAttributeValues()
I get a Set of UserAttributeValue objects.

However, If I try something like that:
Code:
List ls = dataManager.getSession().createFilter( user.getUserAttributeValues(),
                    "where this.userAttribute.name = ?" ).
                    setString( 0, "UserAttribute0" ).list();

it is doomed to failure... :(

Code:
org.hibernate.QueryException: collection of values in filter: this [where this.userAttribute.name = ?]
   at org.hibernate.hql.ast.HqlSqlWalker.prepareFromClauseInputTree(HqlSqlWalker.java:154)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:497)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:98)
   at org.hibernate.impl.SessionFactoryImpl.getFilter(SessionFactoryImpl.java:453)
   at org.hibernate.impl.SessionImpl.getFilterTranslator(SessionImpl.java:1183)
   at org.hibernate.impl.SessionImpl.listFilter(SessionImpl.java:1209)
   at org.hibernate.impl.CollectionFilterImpl.list(CollectionFilterImpl.java:46)
   at com.fresh.uvs.entity.test.core.UserTest.runAdditionalTests(UserTest.java:267)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)



Do I have to turn my composite-element classes into entity classes if I want to do queries like the previous one??

Thanks a lot for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 1:40 am 
Newbie

Joined: Tue Jan 25, 2005 10:07 pm
Posts: 4
I have the same problem!


Anyone can help us?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 2:23 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 7:53 am
Posts: 32
Location: Madrid - Spain
I'll show the mapping that sorted out this problem to me. I hope this help you!

USER:
Code:
.....

        <map
            name="userAttributeValues"
            lazy="true"
            sort="unsorted"
            cascade="save-update"
        >

            <key
                column="USER_ID"
            >
            </key>

            <index
                column="USER_ATTRIBUTE_ID"
                type="int"
            />

            <one-to-many
                  class="x.y.z.UserAttributeValue"
            />

        </map>

.....


USER_ATTRIBUTE:
Code:
<hibernate-mapping
>

    <class
        name="x.y.z.UserAttribute"
        table="CORE_USER_ATTRIBUTE"
    >

        <id
            name="userAttributeId"
            column="USER_ATTRIBUTE_ID"
            type="int"
            length="8"
            unsaved-value="null"
        >
            <generator class="native">
                <param name="sequence">SEQ_CORE_USER_ATTRIBUTE</param>
            </generator>
        </id>

        <many-to-one
            name="service"
            class="x.y.z.Service"
            cascade="save-update"
            outer-join="auto"
            update="true"
            insert="true"
            access="field"
            foreign-key="SERVICE_ID"
            column="SERVICE_ID"
            not-null="true"
        />

        <property
            name="name"
            type="string"
            update="true"
            insert="true"
            column="NAME"
            length="20"
            not-null="true"
        />

        <property
            name="required"
            type="yes_no"
            update="true"
            insert="true"
            column="REQUIRED"
            length="1"
            not-null="false"
        />

    </class>

</hibernate-mapping>


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