-
Hi I'm, using NH 5.2.7 on .NET 4.8 Base class: /// <summary>
/// Base class for all ratings
/// </summary>
public abstract class InternalRatingBase : IRatingBase, IDeletableEntity, IJournalTarget
{
public virtual int Id { get; set; }
/// <summary>
/// <inheritdoc cref="IDeletableEntity.IsDeleted"/>
/// </summary>
public virtual bool IsDeleted { get; set; }
} Base class mapping: <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Cra.VubScoringEngine" namespace="Cra.VubScoringEngine.Domain.Rating">
<class name="InternalRatingBase" table="RatingBase" where="IsDeleted = 0" batch-size="20" polymorphism="explicit">
<id name="Id" type="Int32" unsaved-value="0">
<column name="Id" sql-type="int" not-null="true"/>
<generator class="native" />
</id>
<property name="IsDeleted" type="Boolean">
<column name="IsDeleted" sql-type="bit" not-null="true"/>
</property>
</class>
</hibernate-mapping> Then I have few subclasses like this: public class CompositeRatingFinalisation : InternalRatingBase
{
public virtual string CreatedBy { get; set; }
public virtual bool IsExtension { get; set; }
/// <summary>
/// bidirectional ono-to-one association
/// </summary>
public virtual CompositeRating CompositeRating { get; set; }
} Subclass mapping: <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Cra.VubScoringEngine" namespace="Cra.VubScoringEngine.Entities">
<joined-subclass name="CompositeRatingFinalisation" table="CompositeRatingFinalisation" batch-size="20" extends="Cra.VubScoringEngine.Domain.Rating.InternalRatingBase">
<key column="Id"/>
<!-- CompositeRatingFinalisation properties -->
<property name="CreatedBy" type="String" update="false">
<column name="CreatedBy" sql-type="nvarchar(50)" length="50" not-null="true"/>
</property>
<property name="IsExtension" type="Boolean" update="false">
<column name="IsExtension" sql-type="bit" not-null="true"/>
</property>
<many-to-one name="CompositeRating" class="CompositeRating" update="false" foreign-key="FK_CompositeRatingFinalisation_CompositeRatingId_CompositeRating_Id" unique="true">
<column name="CompositeRatingId" sql-type="int" not-null="true"/>
</many-to-one>
<!-- leaving out properties for simplicity-->
</joined-subclass>
</hibernate-mapping>
Note: Reality is bit more complex as in fact the Now take a look at the <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Cra.VubScoringEngine" namespace="Cra.VubScoringEngine.Entities">
<class name="CompositeRating" table="CompositeRating" batch-size="20" where="IsDeleted = 0">
<id name="Id" type="Int32" unsaved-value="0">
<column name="Id" sql-type="int" not-null="true"/>
<generator class="native" />
</id>
<property name="CreatedBy" update="false">
<column name="CreatedBy" length="50" sql-type="nvarchar(50)" not-null="true"/>
</property>
<property name="IsDeleted">
<column name="IsDeleted" sql-type="bit" not-null="true"/>
</property>
<!-- leaving out properties for simplicity-->
<!-- Generates wrong SQL query for IsDeleted base class field
- can be fixed by using fetch="select" but then batch fetching do not work either
-->
<one-to-one name="Finalisation" class="CompositeRatingFinalisation" property-ref="CompositeRating" fetch="join" />
<!-- <bag name="Finalisations" inverse="true" fetch="join">-->
<!-- <key column="CompositeRatingId"/>-->
<!-- <one-to-many class="CompositeRatingFinalisation"/>-->
<!-- </bag>-->
<bag name="WorkflowLog" inverse="true" batch-size="10">
<key column="CompositeRatingId"/>
<one-to-many class="CompositeRatingWorkflowLog"/>
</bag>
</class>
</hibernate-mapping> Now when I query the NH for SELECT this_.Id as id1_54_1_,
this_.CreatedBy as createdby7_54_1_,
this_.IsDeleted as isdeleted15_54_1_,
compositer2_.Id as id1_31_0_,
compositer2_1_.IsDeleted as isdeleted2_31_0_,
compositer2_.CompositeRatingId as compositeratingid11_57_0_,
compositer2_.CreatedBy as createdby13_57_0_
FROM dbo.CompositeRating this_
left outer join dbo.CompositeRatingFinalisation compositer2_
on this_.Id=compositer2_.CompositeRatingId and (compositer2_1_.IsDeleted = 0)
left outer join dbo.RatingBase compositer2_1_
on compositer2_.Id=compositer2_1_.Id
WHERE ( this_.IsDeleted = 0) AND (this_.CisId = @p0 and not (this_.State = @p1)) ORDER BY this_.Id desc As you can see the WHERE condition from the base If I change Only workaround I found until now is to use one-to-many instead (commented in mapping) which fixes the issue but is not optimal either as I must "simulate" the one-to-one nature of the association in the classes (for example Thx for ideas! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Did you try with latest 5.4.2? Duplicate of #1209
Nope. It shouldn't. |
Beta Was this translation helpful? Give feedback.
Did you try with latest 5.4.2? Duplicate of #1209
Nope. It shouldn't.