I have an Audit object that has a IList<AuditType>.  There is a many-
to-many relationship between Audit and AuditType, which means there is
an "in between table" named Audit_AuditTypes.  I need to select all
the audits that are associated to certain AuditType's.

What would the HQL for this look like?

If Audit only had one reference to AuditType then I could simply do
something like this:
"Select audit from Audit audit where audit.auditType.Id in
(1,2,3,4,etc)"

I have tried this but it fails with a "Path expected for join"
exception:
"Select audit From Audit audit
join audit_auditTypes on audit_auditTypes.auditId = audit.Id
where 0 < (select count(*) from AuditType auditType where auditType.Id
= audit_auditTypes.auditTypeId and auditType.Id IN (:auditTypeIds))"

Here are the mappings:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="Entity"
                   namespace="ClaimAudit.Entity">
    <class name="ClaimAudit.Entity.Audit" lazy="false" table="audits">
        <id name="Id">
            <generator class="native"/>
        </id>
        <property name="Active" type="Boolean"/>
        <property name="DateAudited"/>
        <bag name="AuditTypes" table="audit_auditTypes" lazy="false">
            <key column="auditId"/>
            <many-to-many column="auditTypeId" class="AuditType"/>
        </bag>
    </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="Entity"
                   namespace="ClaimAudit.Entity">
    <class name="ClaimAudit.Entity.AuditType" lazy="false"
table="audittypes">
        <id name="Id">
            <generator class="native"/>
        </id>
        <property name="Active" type="Boolean"/>
        <property name="Name"/>
        <property name="Description"/>
    </class>
</hibernate-mapping>
-- 
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