-->
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.  [ 1 post ] 
Author Message
 Post subject: HQL on a collection property defined on a pivot table
PostPosted: Mon Sep 13, 2010 12:15 pm 
Newbie

Joined: Mon Sep 13, 2010 11:47 am
Posts: 1
Hi Guys,

I am trying to write HQL on entities linked in a ternary relationship.

I have tables Team, Attribute and a pivot table TeamAttributeMap. But along with the relationship the pivot table also stores a value that is related to the mapping team and attribute mapping.

After a lot digging around. I could establish this relationship as follows:

Team - Hibernate Mapping (excluding id and other properties)
Code:
<idbag name="attributesAndValues" table="TEAM_ATTRIBUTE_MAP" cascade="all-delete-orphan" lazy="true">
       <collection-id column="TEAM_ATTRIPUTE_MAP_ID" type="long">
           <generator class="sequence">
              <param name="sequence">TEAM_ATTRIBUTE_MAP_SEQUENCE</param>
           </generator>
       </collection-id>
       <key column="TEAM_ID" not-null="true"/>
       <composite-element class="Team$AttributeValue">
          <property name="value" column="TEAM_ATTRIBUTE_VALUE" not-null="true" unique="true"/>
          <many-to-one name="attribute" class="Attribute" column="ATTRIBUTE_ID" cascade="none" not-null="true" fetch="join"/>
       </composite-element>      
   </idbag>


Now i amt trying to write hql like
Code:
stringBuilder.append(" from Team team where ");
            stringBuilder.append(" team.attributesAndValues.size <= :attributesAndValuesSize  ");
            stringBuilder.append(" and team.attributesAndValues = :attributesAndValues ");
            Query query = session.createQuery(stringBuilder.toString());
            query.setParameter("attributesAndValuesSize", attributesAndValues.size());
            
            query.setParameterList("attributesAndValues[]", attributesAndValues);



But hibernate is generating wrong quries like
[quote]

Code:
select
        team0_.ID as ID5_,
        team0_.LAST_MODIFIED_BY as LAST2_5_,
        team0_.LAST_MODIFIED_DATE as LAST3_5_,
        team0_.NAME as NAME5_,
        team0_.CODE as CODE5_,
        team0_.DESCRIPTION as DESCRIPT6_5_
    from
        RMS3.TEAM team0_ cross
    join
        RMS3.TEAM_ATTRIBUTE_MAP attributes2_
    where
        team0_.ID=attributes2_.TEAM_ID
        and (
            select
                count(attributes1_.TEAM_ID)
            from
                RMS3.TEAM_ATTRIBUTE_MAP attributes1_
            where
                team0_.ID=attributes1_.TEAM_ID
        )<=?
        and .=?

can any body tell me what am doing wrong herer.

Thanks,
Amit


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.