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