The where attribute must contain SQL, not HQL.
Hi. I'm new to NHibernate. I have an old database that I have to do some mappings on it.
The below database is an example of my problem (not the same).
Database:
Class Diagram:
I want to fill MaleActors with Actors that their Sex field equals to 'Male' and FemaleActors with Actors that their Sex field equals to 'Female'
I tried where attribute on my many-to-many relation but it doesn't work.
Here are my Mapping files:
Movie.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MovieEg" namespace="MovieEg">
<class name="Movie" table="Movies">
<id name="Id">
<generator class="identity"/>
</id>
<property name="Name"/>
<bag name="FActors" table="ActorRoles" >
<key column="MovieId"/>
<many-to-many class="Role" column="Id" where="Actors.Sex='Male'" />
</bag>
</class>
</hibernate-mapping>
Actor.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MovieEg" namespace="MovieEg">
<class name="Actor" table="Actors">
<id name="Id">
<generator class="identity"/>
</id>
<property name="Name"/>
<property name="Sex"/>
</class>
</hibernate-mapping>
ActorRole.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MovieEg" namespace="MovieEg">
<class name="Role" table="ActorRoles">
<id name="Id">
<generator class="identity"/>
</id>
<property name="RoleNameInMovie" column="Role"/>
<many-to-one name="Actor" class="Actor" column="ActorId" />
</class>
</hibernate-mapping>