Hello,
I have the following situation in my hbm.xml file and I need to check the Profile.Name attribute in my query using the following code:
ICriteria c = s.OpenSession().CreateCriteria(typeof(ObjectModel.Auth.ProfileActionProperty));
c.CreateAlias("Action", "act");
c.CreateAlias("act.Profile","actpro");
c.Add(NHibernate.Expression.Expression.Eq("act.Profile.Name","my profile name"));
Problem 1: as you can see in the generated-sql section the istruction c.CreateAlias("act.Profile","actpro") is ignored because no joins are created. Consequently I have an exception for "....alias not found..."
Problem 2: it always creates an inner join (I need left outer join in my query); i tried to change this default setting using SetFetchMode("act", FetchMode.Join) without success.
Someone can help me?
Thanks
Antonella
Hibernate version: 1.0.2
Mapping documents:
<class name="ObjectModel.Auth.Profile, ObjectModel" table="Auth_Profile">
<id name="Id" type="Int32" column="Id" access="field.pascalcase-m-underscore">
<generator class="hilo">
<param name="table">NH_Key_Auth</param>
<param name="column">Auth_Profile</param>
<param name="max_lo">0</param>
</generator>
</id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<property name="Description" column="Description" type="String" />
<property name="Name" column="Name" type="String" />
</class>
<class name="ObjectModel.Auth.ProfileAction, ObjectModel" table="Auth_ProfileAction">
<composite-id>
<key-many-to-one name="Action" class="ObjectModel.Auth.Action, ObjectModel" column="IdAction" />
<key-many-to-one name="Profile" class="ObjectModel.Auth.Profile, ObjectModel" column="IdProfile" />
</composite-id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<bag name="profileactionproperties" inverse ="false" cascade="all">
<key>
<column name="IdAction" />
<column name="IdProfile" />
</key>
<one-to-many class="ObjectModel.Auth.ProfileActionProperty, ObjectModel" />
</bag>
</class>
<class name="ObjectModel.Auth.ProfileActionProperty, ObjectModel" table="Auth_ProfileActionProperty">
<id name="Id" type="Int32" column="Id" access="field.pascalcase-m-underscore">
<generator class="hilo">
<param name="table">NH_Key_Auth</param>
<param name="column">Auth_ProfileActionProperty</param>
<param name="max_lo">0</param>
</generator>
</id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<many-to-one name="Action" class="ObjectModel.Auth.ProfileAction, ObjectModel" cascade="none">
<column name="IdAction" />
<column name="IdProfile" />
</many-to-one>
</class>
Name and version of the database you are using: SQLServer 2000
The generated SQL (show_sql=true):
SELECT
{...}
FROM dbo.Auth_ProfileActionProperty this
{...}
inner join dbo.Auth_ProfileAction act ON this.IdAction=act.IdAction AND this.IdProfile=act.IdProfile
WHERE actpro.Name = @p0
@p0 = 'my profile name'
|