-->
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.  [ 2 posts ] 
Author Message
 Post subject: Querying a many-to-many mapping
PostPosted: Thu Feb 23, 2006 8:57 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
I have a unidirectional many to many mapping between two entites Visitor and Stands....i have a lookup table vcfBusinesscards which is used for this mapping.

I need a named query tell me if there are any mappings between a specific visitor and specific stand given there ids.

i tried this:
<query name="Visitor.Bookmarked">from Visitor v where v.BCStands.Code=? and v.Id = ?</query>

but got this error:
NHibernate.QueryException: expecting 'elements' or 'indices' after Code [from vcf.code.entites.users.Visitor v where v.BCStands.Code=? and v.Id = ?]



Visitor Entity:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="vcf.code.entites.users.Visitor,vcf" table="vcfVisitors">

      <id name="Id" column="code" type="Int32" unsaved-value="0">
         <generator class="native"/>
      </id>
      <set name="BCStands" table="vcfBusinessCard">
         <key column="visitor_id"/>
         <many-to-many column="stand_id" class="vcf.code.entites.Stand,vcf"/>
      </set>
   </class>
   
   <query name="Visitor.Get">from Visitor where user_code= ?</query>

</hibernate-mapping>


Stand Entity:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="vcf.code.entites.Stand,vcf" table="vcfStands">
      <id name="Code" column="code" type="Int32">
         <generator class="native"/>
      </id>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 12:30 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
What you have written will not work because v.BCStands is a collection. Try this:

from Visitor v where ? in (select s.Code from v.BCStands s) and v.Id = ?

This should do for you


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