-->
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: Simple Query giving me a headache
PostPosted: Mon Jul 19, 2004 3:27 pm 
Newbie

Joined: Thu Jun 17, 2004 1:09 pm
Posts: 9
I wish to execute a query where I return all the people that belong to a specific phone number. The names of the people are in a table that is separate from the phone numbers. The HBM files are as follows:

Code:

<hibernate-mapping>

<class name="zarnett.at.mac.maschool.addressBook.dataModels.Student" table="STUDENT">

<id name="id" type="int" column="STUDENT_ID">
  <meta attribute="scope-set">protected</meta>
  <generator class="native"/>
</id>

<property name="firstName" type="string" not-null="true">
  <meta attribute="use-in-tostring">true</meta>
  <column name="FIRST_NAME" not-null="true" index="TRACK_TITLE"/>
</property>

<property name="lastName" type="string" not-null="true">
  <meta attribute="use-in-tostring">true</meta>
  <column name="LAST_NAME" not-null="true"   
       index="LAST_NAME_INDEX"/>
</property>

<property name="studentCode" type="string" not-null="true">
  <meta attribute="use-in-tostring">true</meta>
  <column name="STUDENT_CODE" not-null="true"
       index="STUDENT_CODE_INDEX"/>
</property>

<set name="contactDetails" table="STUDENT_CONTACT">
  <key column="STUDENT_CODE"/>
  <many-to-many class="zarnett.at.mac.maschool.addressBook.dataModels.ContactDetails"
         
       column="CONTACT_DETAILS_ID"/>
</set>

</class>


</hibernate-mapping>




and

Code:

<hibernate-mapping>

<class name="zarnett.at.mac.maschool.addressBook.dataModels.ContactDetails" table="CONTACT_DETAILS">

<id name="id" type="int" column="CONTACT_DETAILS_ID">
  <meta attribute="scope-set">protected</meta>
  <generator class="native"/>
</id>

<property name="contactType" type="int" not-null="true">
  <meta attribute="use-in-tostring">true</meta>
  <column name="CONTACT_TYPE" not-null="true"/>
</property>

<property name="contactData" type="string" not-null="true">
  <meta attribute="use-in-tostring">true</meta>
  <column name="CONTACT_DATA" not-null="true" />
</property>

</class>
   
   
</hibernate-mapping>



I should be able to say "given phone number 867-5309" give me all the people with that phone number.

Can anyone give me the HSQL call that would allow such a query to take place? I'm probably making the ones I tried more complicated than they need to be and thus, the errors.

Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 3:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
select s from Student s join s.contactDetails cd where cd.phoneNumber = :phoneNumber

But I don't see any phone number property, so your question is kinda wierd....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 3:56 pm 
Newbie

Joined: Thu Jun 17, 2004 1:09 pm
Posts: 9
Sorry, the contactData is where the phone number is and the contactType would be a number such as 1 which indicates the type of contact data, for instance, a home phone number.

Thank you very much for the example.


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.