Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring.Net HibernateTemplate.Execute Clarification
    primarykey
    data
    text
    <p>I am taking over a project that was written by third party consultants who have already left.</p> <p>I come from EF backgournd. One of the DAO class has the following which I find very hard to get my head around on details of what is exactly happening step by step. If anyone could kindly help me to understand this code section will be much appreciated.</p> <pre><code>return HibernateTemplate.Execute( delegate(ISession hbSession) // &lt;&lt;--What is this code actually trying to do? { string queryText = "from {0} x where x.Code = :Code"; queryText = string.Format(queryText, typeof(Product)); IQuery query = hbSession.CreateQuery(queryText); query.SetParameter("Code", productCode); query.SetCacheable(true); query.SetCacheRegion(CoreCacheConstants.ProductQueryCacheRegion); // &lt;-- What is this code trying to do. var fund = query.UniqueResult(); // &lt;-- Is this similar to DISTINCT keyword in LINQ? if (fund == null) throw new ArgumentException(String.Format("No product found with productcode: {0}", productCode: )); NHibernateUtil.Initialize(((Product)Product).Details); // &lt;--What is this code trying to do. And where is the execute method for above queries. return fund; } ) as Product </code></pre> <p>Basically I am confused with delegate part and why delegate is being used instead of simple query to database. And what is the benefit of above approach.</p> <p>Also I cant see any nHibernate ORM mapping xml. Does Spring.NET requires mapping files in order to pass data from/to data source?In order words how does ISession knows which database to connect to and which table to use etc</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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