-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using a component in a where clause
PostPosted: Tue Apr 29, 2008 5:59 am 
Newbie

Joined: Tue Apr 22, 2008 7:17 am
Posts: 14
Hi,

I've searched in the documentation and FAQs but can't seem to find out exactly how you are able to specify a component in the where clause of a query.

I have a component in my Question entity called Domain and would like to be able write a query like:

session.createQuery("select distinct q.Subdomain from Question q where q.Domain= :domain")

However I can't use setEntity, or setParameter it seems if I am supplying an instance of the component.

The documentation says I can do this, but doesn't show how to actually set the value of the component in the query.

Thanks,
Matt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 29, 2008 7:03 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
"setParameter" should be fine, AFAIK you don't need to have some special behavior on components.
Are you sure your query shouldn't have properties lowercase?
I would have written something like
Code:
session.createQuery("select distinct q.subdomain from Question q where q.somain= :domain")


If this doesn't help you you should post the source of your entities.

regards,

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 29, 2008 5:57 pm 
Newbie

Joined: Tue Apr 22, 2008 7:17 am
Posts: 14
I'm actually working with .Net so my properties have uppercase...

I'm assuming the parameter setting will be the same tho in the two versions.

My mapping file looks like this:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                  assembly="OzoneHR.Domain"
                  namespace="OzoneHR.Domain.Questionnaires">
  <class name="Question" table="Question">
    <id name="QuestionId" access="nosetter.camelcase-underscore"
      column="QuestionId" type="Int32">
      <generator class="identity" />
    </id>
    <property name="QuestionText" column="QuestionText" type="String" length="400" not-null="true" />
    <component name="Subdomain" class="QuestionnaireSubdomain">
      <property name="SubdomainName" access="nosetter.camelcase-underscore" column="Subdomain" />
    </component>
    <component name="Domain" class="QuestionnaireDomain">
      <property name="DomainName" access="nosetter.camelcase-underscore" column="Domain" />
    </component>
    <property name="OrderPosition" type="Int32" not-null="true" />
    <many-to-one name="QuestionnaireSection" access="nosetter.camelcase-underscore" column="QuestionnaireSectionID"
                 class="QuestionnaireSection" not-null="true" />
  </class>
</hibernate-mapping>


And my code looks like:

Code:
session.CreateQuery("select distinct q.Subdomain from Question q where q.Domain = :domain")
                .SetParameter("domain", domain)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 2:12 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
I'm actually working with .Net so my properties have uppercase...
I'm assuming the parameter setting will be the same tho in the two versions.


Yes I would think the same too, but you should maybe ask to the .Net forum, they probably know it better.

http://forum.hibernate.org/viewforum.php?f=25

regards,

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 3:35 am 
Newbie

Joined: Tue Apr 22, 2008 7:17 am
Posts: 14
Ok thanks I will. I've tried there with a couple of other queries and not had much luck with responses.

Thanks,
Matt


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