Note that there are some explanatory texts on larger screens.

plurals
  1. PONhibernate select query triggers Update statement - unintended, Why?
    text
    copied!<p>I have the following code wich causes an Update on the DB as calling Commit().</p> <pre><code>using (ISession t = DBSessionManager.GetDBSessionController(Database).GetDBSession()) { using (var tx = t.BeginTransaction()) { var o = t.Linq&lt;Appendix&gt;(); o.Expand("Instruments"); o.Expand("Language"); o.Expand("MifidCompliance"); o.Expand("IBAppendix"); var ret = (from ss in o where ss.AppendixHierachy.id == hierarchyId select ss).ToList(); tx.Commit(); return ret; //this hql also causes the updates string hqlString = "select a from Appendix as a join fetch a.Language as l join fetch a.MifidCompliance as mifid left join fetch a.Instruments i left join a.IBAppendix as ib where a.AppendixHierachy = " + hierarchyId; IQuery query = t.CreateQuery(hqlString); var items = query.List&lt;Appendix&gt;(); tx.Commit(); return (List&lt;Appendix&gt;)items; } } </code></pre> <p>It seems to update with Commit all the appendix which fullfill the restriction.(NH Profiler)</p> <pre><code>UPDATE appendix SET appendix = '0x255044462D312E340A25C7E461215928AE3FBD7DF6F17204439AE9AF...' /* @p0_0 */, creatorEmpId = 0 /* @p1_0 */, disclaimerOffset = 0 /* @p2_0 */, fileExtension = 'PDF' /* @p3_0 */, publishedDate = '2008-10-02T18:34:50.00' /* @p4_0 */, reportPositionId = 0 /* @p5_0 */, summary = ' summaryText...' /* @p6_0 */, thumbnail = '0xFFD8...' /* @p7_0 */, title = 'Nitto Denko - Upgrade: Pessimism already priced in' /* @p8_0 */, appendixHierarchyId = 12 /* @p9_0 */, languageId = 101 /* @p10_0 */, MifidComplianceId = 110 /* @p11_0 */ WHERE id = 337815 /* @p12_0 */ </code></pre> <p>Why is that? If the is some IBAppendix available then it works without updates: Here is the mapping:</p> <pre><code>public class IBAppendixMap : ClassMap&lt;IBAppendix&gt; { public IBAppendixMap() { Id(x =&gt; x.id).GeneratedBy.Foreign("Appendix"); Map(x =&gt; x.RIXMLProductID); References(x =&gt; x.Appendix).Column("Appendix_id"); } } public class AppendixMap : ClassMap&lt;Appendix&gt; { public AppendixMap () { Table("appendix"); Id(x =&gt; x.id).GeneratedBy.Custom(typeof(ATKIdGenerator), a =&gt; a.AddParam("TableName", "appendix")); References(x =&gt; x.AppendixHierachy).Column("appendixHierarchyId").Not.Nullable(); Map(x =&gt; x.appendix); Map(x =&gt; x.creatorEmpId); Map(x =&gt; x.disclaimerOffset); Map(x =&gt; x.fileExtension); References(x =&gt; x.Language).Column("languageId"); References(x =&gt; x.MifidCompliance).Column("MifidComplianceId"); Map(x =&gt; x.publishedDate); Map(x =&gt; x.reportPositionId); Map(x =&gt; x.summary).Length(7000); Map(x =&gt; x.thumbnailbyte).Column("thumbnail"); Map(x =&gt; x.title); HasManyToMany(x =&gt; x.Instruments).Table("instAppendix").ParentKeyColumn("appendixId").ChildKeyColumn("instId"); HasOne( x =&gt; x.IBAppendix).Cascade.All(); } } </code></pre> <p>I never expected that some simple select would cause an update on the db! Has anyone ideas why that is?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload