I have many to many Mapping between Company table to Contact table
using Company_Contact_role table
Company_Contact_role Table has Company_Contact_role_Id,
CompanyId,ContactId,Contact_type_Code

Here is my mapping


  <class name="CompayEntity" table="Company" >
      <map name="Contacts" table="Company_Contact_ROLE" >
      <key column="Companyd"/>
      <index column="Contact_TYPE_CODE" type="System.String"/>
      <many-to-many class="ContactEntity"
        column="ContactID"/>
    </map>
  </class>

The mapping work great as i expected.  But i am facing two issue .

Intermediate table has a sequence Key called
Company_Contact_RoleIdSeq. It needs to be populated when a new row is
added.
I am not quite sure how to add  geneartor to the mapping table.

I tried following syntax it did not work
 <map name="Contacts" table="Company_Contact_ROLE" >
      <key column="Companyd">
         <generator class="sequence">
        <param name="sequence">Company_Contact_Role_IDSeq</param>
      </generator>
        </Key>
      <index column="Contact_TYPE_CODE" type="System.String"/>
      <many-to-many class="ContactEntity"
        column="ContactID"/>
    </map>



Question 2: how do i create HQL Alias to Indexed collection


  <query name="CompnayContactsByRole.FindByCriteria">
    <![CDATA[
        select entity
        from  CompayEntity  entity
        where entity.Contacts['Primary'].ContactFirstName='bob'


    ]]>
  </query>

The above code returns list of all company bob is dealing with.

But the SQL is not using inner joins instead it uses where clause to
join all.
select  *
from company
where (Contact.ContactFirstName='Jamelia' )and
     ('Primary' in Company_Contact_role.ContactId )and
     ( company.CompanyID=Company_Contact_ROLE.CompanyID)



I Prefer to use  join but HQL throws exception
I tried follwoing two different syntax nothing worked.
        select entity
        from  CompayEntity  entity
         join entity.Contacts cont
        where cont['Primary'].ContactFirstName='bob'
or

        select entity
        from  CompayEntity  entity
         join entity.Contacts contColl
        where 'Primary' in contColl and
contColl.ContactFirstName='bob'


  Is there a better way to add Alias to an indexed Collection

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to