-->
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: hql with <composite-element> ???
PostPosted: Fri Feb 13, 2009 6:28 am 
Newbie

Joined: Wed Jan 21, 2009 4:26 pm
Posts: 12
Hi guys,
i have a problem to use the hql-statement below. My mapping looks as follow:

How can make a hql-statement to use an object within a composite-element structure? I know that you can only use mapped classes.
I did not find any other proper solution!
Do you have any ideas? Any help would be very appreciated. Thanks

Code:
<hibernate-mapping default-access="field" default-lazy="false">
<class name=Car table="CAR">

<property name="description" type="string">
       <column name="description" length="200" />
</property>

<list name="equipmentChoices" table="Car_Equipment" inverse="false">
   <key column="CAR_ID" />
   <list-index column="Car_Equipment_ID" />
   <composite-element class="EquipmentChoice">
      <property name="released" column="Released" type="boolean"/>
       <many-to-one name="equipment" class="Equipment" column="Equipment_Id" />
   </composite-element>
</list>

</class>
<hibernate-mapping>

hql:
Code:
select c from Car c
where exists (select count(*) from c.equipmentChoices ec where ec.equipment.id = ?)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 10:41 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Try this-

SELECT c FROM Car as c WHERE EXISTS ( FROM EquipmentChoice as ec WHERE ec.equipment.id = :equipementId AND ec=c.equipmentChoices);


Last edited by parmendratyagi on Fri Feb 13, 2009 11:43 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 11:41 am 
Newbie

Joined: Wed Jan 21, 2009 4:26 pm
Posts: 12
Thanks for your reply!

It does not work either! I get the exception:

Code:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property


What I figured is, if I refer to another property of Equipment, then it works somehow. But if I refer to id of Equipment, then it fails:
For example:

Code:
select c from Car c
where exists (select count(*) from c.equipmentChoices ec where ec.equipment.name = 'leather')   // THIS WORKS


Code:
//HACK works
select c from Car c
where exists (select count(*) from c.equipmentChoices ec where ec.equipment.name = (select name from Equipment where id = ?) )


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 11:43 am 
Newbie

Joined: Wed Jan 21, 2009 4:26 pm
Posts: 12
Why is refering to object id not working???

Does somebody has an answer for me?

thanks in advance


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.