<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://nhforge.org/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>From 1.0 to 1.2</title><link>http://nhforge.org/wikis/reference2-0en/from-1-0-to-1-2.aspx</link><description>Read reference documentation for a number of NHibernate 2.0 APIs. </description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>From 1.0 to 1.2</title><link>http://nhforge.org/wikis/reference2-0en/from-1-0-to-1-2.aspx</link><pubDate>Mon, 11 May 2009 15:01:40 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:59</guid><dc:creator>Fabio Maulo</dc:creator><comments>http://nhforge.org/wikis/reference2-0en/from-1-0-to-1-2/comments.aspx</comments><description>Current revision posted to NHibernate 2.0  by Fabio Maulo on 11/05/2009 12:01:40 p.m.&lt;br /&gt;
&lt;p&gt;
&lt;h2&gt;NHibernate 1.2&lt;/h2&gt;
&lt;p&gt;NHibernate 1.2 is mostly source-compatible with NHibernate 1.0. However, it is not intended as a drop-in replacement for 1.0.&lt;/p&gt;
&lt;p&gt;This document describes the changes between NHibernate 1.0 and NHibernate 1.2 that will affect existing applications, and mentions certain new features of NHibernate 1.2 that might be useful to existing applications.&lt;/p&gt;
&lt;p&gt;Changes are classified into&amp;nbsp;&lt;em&gt;API changes&lt;/em&gt;&amp;nbsp;(affecting source code),&amp;nbsp;&lt;em&gt;metadata changes&lt;/em&gt;&amp;nbsp;(affecting the XML O/R mapping metadata),&amp;nbsp;&lt;em&gt;query language changes&lt;/em&gt;&amp;nbsp;(affecting HQL queries),&amp;nbsp;&lt;em&gt;runtime behavior changes&lt;/em&gt;, and&amp;nbsp;&lt;em&gt;security-related changes&lt;/em&gt;.&lt;/p&gt;
&lt;a name="A3"&gt;&lt;/a&gt;
&lt;h3&gt;API Changes&lt;/h3&gt;
&lt;a name="A4"&gt;&lt;/a&gt;
&lt;h4&gt;&lt;tt&gt;ISession&lt;/tt&gt;&amp;nbsp;interface&lt;/h4&gt;
&lt;p&gt;Redundant query execution methods were deprecated in&amp;nbsp;&lt;tt&gt;ISession&lt;/tt&gt;&amp;nbsp;interface. These methods are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;Find()&lt;/tt&gt;,&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;Enumerable()&lt;/tt&gt;,&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;Filter()&lt;/tt&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;NHibernate 1.2 applications should use&amp;nbsp;&lt;tt&gt;CreateQuery()&lt;/tt&gt;&amp;nbsp;for all query execution. Existing applications may continue to use the deprecated methods.&lt;/p&gt;
&lt;a name="A5"&gt;&lt;/a&gt;
&lt;h4&gt;&lt;tt&gt;ISession.CreateSQLQuery()&lt;/tt&gt;&lt;/h4&gt;
&lt;p&gt;The overloaded forms of&amp;nbsp;&lt;tt&gt;CreateSQLQuery()&lt;/tt&gt;&amp;nbsp;which took arrays have been deprecated. There is a new&amp;nbsp;&lt;tt&gt;ISQLQuery&lt;/tt&gt;&amp;nbsp;interface (returned by&amp;nbsp;&lt;tt&gt;CreateSQLQuery(String)&lt;/tt&gt;) which provides equivalent functionality (and more). Existing applications may continue to use the deprecated methods.&lt;/p&gt;
&lt;a name="A6"&gt;&lt;/a&gt;
&lt;h4&gt;&lt;tt&gt;ILifecycle&lt;/tt&gt;&amp;nbsp;and&amp;nbsp;&lt;tt&gt;IValidatable&lt;/tt&gt;&amp;nbsp;interfaces&lt;/h4&gt;
&lt;p&gt;The&amp;nbsp;&lt;tt&gt;ILifecycle&lt;/tt&gt;&amp;nbsp;and&amp;nbsp;&lt;tt&gt;IValidatable&lt;/tt&gt;&amp;nbsp;interfaces were deprecated in NHibernate 1.2 and moved to the&amp;nbsp;&lt;tt&gt;NHibernate.Classic&lt;/tt&gt;&amp;nbsp;namespace. The Hibernate team does not consider it good practice to have domain model classes depend upon persistence-specific APIs. NHibernate 1.2 applications should use&amp;nbsp;&lt;tt&gt;IInterceptor&lt;/tt&gt;&amp;nbsp;interface. Existing applications may continue to use&amp;nbsp;&lt;tt&gt;ILifecycle&lt;/tt&gt;&amp;nbsp;and&amp;nbsp;&lt;tt&gt;IValidatable&lt;/tt&gt;.&lt;/p&gt;
&lt;a name="A7"&gt;&lt;/a&gt;
&lt;h4&gt;&lt;tt&gt;IInterceptor&lt;/tt&gt;&amp;nbsp;interface&lt;/h4&gt;
&lt;p&gt;Several new methods were added to the&amp;nbsp;&lt;tt&gt;IInterceptor&lt;/tt&gt;&amp;nbsp;interface. Existing interceptors will need to be ugraded to provide empty implementations of the two new methods.&lt;/p&gt;
&lt;p&gt;To avoid issues with interceptor migration (whether 1.0.x -&amp;gt; 1.2.x, or moving forward), just extend the new&amp;nbsp;&lt;tt&gt;EmptyInterceptor&lt;/tt&gt;&amp;nbsp;class instead of writing your own empty implementation for all methods you don&amp;#39;t need.&lt;/p&gt;
&lt;a name="A8"&gt;&lt;/a&gt;
&lt;h4&gt;&lt;tt&gt;IUserType&lt;/tt&gt;&amp;nbsp;and&amp;nbsp;&lt;tt&gt;ICompositeUserType&lt;/tt&gt;&amp;nbsp;interfaces&lt;/h4&gt;
&lt;p&gt;Both&amp;nbsp;&lt;tt&gt;IUserType&lt;/tt&gt;&amp;nbsp;and&amp;nbsp;&lt;tt&gt;ICompositeUserType&lt;/tt&gt;&amp;nbsp;had several methods added, to support new functionality of NHibernate 1.2. They were moved to the namespace&lt;tt&gt;NHibernate.UserTypes&lt;/tt&gt;. Existing user type classes will need to be upgraded to implement the new methods.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt;&amp;nbsp;NHibernate 1.2 provides&amp;nbsp;&lt;tt&gt;IParameterizedType&lt;/tt&gt;&amp;nbsp;interface to allow better re-useability of user type implementations.&lt;/p&gt;
&lt;a name="A9"&gt;&lt;/a&gt;
&lt;h4&gt;&lt;tt&gt;FetchMode&lt;/tt&gt;&lt;/h4&gt;
&lt;p&gt;&lt;tt&gt;FetchMode.Lazy&lt;/tt&gt;&amp;nbsp;and&amp;nbsp;&lt;tt&gt;FetchMode.Eager&lt;/tt&gt;&amp;nbsp;were deprecated. The more accurately named&amp;nbsp;&lt;tt&gt;FetchMode.Select&lt;/tt&gt;&amp;nbsp;and&amp;nbsp;&lt;tt&gt;FetchMode.Join&lt;/tt&gt;&amp;nbsp;have the same effect.&lt;/p&gt;
&lt;a name="A10"&gt;&lt;/a&gt;
&lt;h4&gt;Changes to extension APIs&lt;/h4&gt;
&lt;p&gt;The&amp;nbsp;&lt;tt&gt;NHibernate.Expression&lt;/tt&gt;,&amp;nbsp;&lt;tt&gt;NHibernate.Mapping&lt;/tt&gt;,&amp;nbsp;&lt;tt&gt;NHibernate.Persister&lt;/tt&gt;&amp;nbsp;and&amp;nbsp;&lt;tt&gt;NHibernate.Collection&lt;/tt&gt;&amp;nbsp;namespaces feature heavy refactoring. Most NHibernate 1.0 applications do not depend upon these namespaces, and will not be affected. If your application&amp;nbsp;&lt;em&gt;does&lt;/em&gt;&amp;nbsp;extend classes in these namespaces, you will need to carefully migrate the affected code.&lt;/p&gt;
&lt;a name="A11"&gt;&lt;/a&gt;
&lt;h3&gt;Metadata Changes&lt;/h3&gt;
&lt;a name="A12"&gt;&lt;/a&gt;
&lt;h4&gt;Association fetching strategies&lt;/h4&gt;
&lt;p&gt;Since it is best practice to map almost all classes and collections using&amp;nbsp;&lt;tt&gt;lazy=&amp;quot;true&amp;quot;&lt;/tt&gt;, that is now the default. Existing applications will need to explicitly specify&amp;nbsp;&lt;tt&gt;lazy=&amp;quot;false&amp;quot;&lt;/tt&gt;on all non-lazy class and collection mappings. For the lazy classes to function correctly, all their public and protected members must be virtual (overridable). Since this is a very significant potential source of errors when developing on .NET, NHibernate 1.2 will check at configuration time that all lazy classes fulfill the requirements.&lt;/p&gt;
&lt;p&gt;The&amp;nbsp;&lt;tt&gt;outer-join&lt;/tt&gt;&amp;nbsp;attribute is deprecated. Use fetch=&amp;quot;join&amp;quot; and fetch=&amp;quot;select&amp;quot; instead of outer-join=&amp;quot;true&amp;quot; and outer-join=&amp;quot;false&amp;quot;. Existing applications may continue to use the&lt;tt&gt;outer-join&lt;/tt&gt;&amp;nbsp;attribute, or may use a text search/replace to migrate to use of the&amp;nbsp;&lt;tt&gt;fetch&lt;/tt&gt;&amp;nbsp;attribute.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Beware, this means you have to put lazy=&amp;quot;false&amp;quot; on all collection mappings and classes which previously did not have a &amp;quot;lazy&amp;quot;-attribute.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A quick and dirty alternative for migration is also to put default-lazy=&amp;quot;false&amp;quot; on all your hibernate-mapping elements.&lt;/p&gt;
&lt;a name="A13"&gt;&lt;/a&gt;
&lt;h4&gt;Schema namespace&lt;/h4&gt;
&lt;p&gt;Update the XML schema reference in your hbm XML files. Change&amp;nbsp;&lt;tt&gt;urn:nhibernate-mapping-2.0&lt;/tt&gt;&amp;nbsp;to&amp;nbsp;&lt;tt&gt;urn:nhibernate-mapping-2.2&lt;/tt&gt;&amp;nbsp;in the&amp;nbsp;&lt;tt&gt;hibernate-mapping&lt;/tt&gt;&amp;nbsp;element. If you get &amp;quot;XML validation error: Could not find schema information for the element &amp;#39;urn:nhibernate-mapping-2.0:hibernate-mapping&amp;#39;&amp;quot;, you forgot to change the namespace.&lt;/p&gt;
&lt;a name="A14"&gt;&lt;/a&gt;
&lt;h4&gt;One-to-many association to a subclass requires explicit&amp;nbsp;&lt;tt&gt;where&lt;/tt&gt;&amp;nbsp;attribute.&lt;/h4&gt;
&lt;p&gt;If you have a one-to-many association to a class that is part of a&amp;nbsp;&lt;tt&gt;subclass&lt;/tt&gt;&amp;nbsp;hierarchy (i.e. using table-per-class-hierarchy strategy), you may need to add a&amp;nbsp;&lt;tt&gt;where&lt;/tt&gt;&amp;nbsp;attribute to the collection element since NHibernate no longer adds the discriminator restriction automatically.&lt;/p&gt;
&lt;p&gt;This is probably best explained in code. The mapping below will no longer work as intended:&lt;/p&gt;
&lt;pre class="code"&gt;&amp;lt;class name=&amp;quot;Person&amp;quot;&amp;gt;
   ...
   &amp;lt;!-- Cat and Dog are subclasses of Animal, mapped using &amp;lt;subclass&amp;gt; --&amp;gt;
   &amp;lt;bag name=&amp;quot;Cats&amp;quot;&amp;gt;
      &amp;lt;one-to-many class=&amp;quot;Cat&amp;quot; /&amp;gt;
   &amp;lt;/bag&amp;gt;

   &amp;lt;bag name=&amp;quot;Dogs&amp;quot;&amp;gt;
      &amp;lt;one-to-many class=&amp;quot;Dog&amp;quot; /&amp;gt;
   &amp;lt;/bag&amp;gt;
&amp;lt;/class&amp;gt;
&lt;/pre&gt;
&lt;p&gt;To make it work again, add explicit&amp;nbsp;&lt;tt&gt;where&lt;/tt&gt;&amp;nbsp;attributes:&lt;/p&gt;
&lt;pre class="code"&gt;&amp;lt;class name=&amp;quot;Person&amp;quot;&amp;gt;
   ...
   &amp;lt;bag name=&amp;quot;Cats&amp;quot; where=&amp;quot;discriminator = &amp;#39;CAT&amp;#39;&amp;quot;&amp;gt;
      &amp;lt;one-to-many class=&amp;quot;Cat&amp;quot; /&amp;gt;
   &amp;lt;/bag&amp;gt;

   &amp;lt;bag name=&amp;quot;Dogs&amp;quot; where=&amp;quot;discriminator = &amp;#39;DOG&amp;#39;&amp;quot;&amp;gt;
      &amp;lt;one-to-many class=&amp;quot;Dog&amp;quot; /&amp;gt;
   &amp;lt;/bag&amp;gt;
&amp;lt;/class&amp;gt;
&lt;/pre&gt;
&lt;a name="A15"&gt;&lt;/a&gt;
&lt;h3&gt;Runtime Changes&lt;/h3&gt;
&lt;a name="A16"&gt;&lt;/a&gt;
&lt;h4&gt;Database connection release mode&lt;/h4&gt;
&lt;p&gt;In NHibernate 1.0 a session acquired a database connection when needed and then held onto to it until closed. As of 1.2, however, the session will release the connection after the database transaction completes. If you are not using NHibernate transactions, the session assumes it is in auto-commit mode, and will release the connection after every operation. The session will automatically re-acquire connection the next time it is needed.&lt;/p&gt;
&lt;p&gt;This behavior can be overridden, but typically it is best to not override this default (unless you are using NHibernate with distributed transactions, in which case the default behavior is inappropriate). If your application depends on some quirk of the old behavior (like having the same connection available beyond transaction boundaries, etc) then you may need to tweak this; but you should view this as a problem with your application logic and fix that. Or, if you believe that you can &amp;quot;read data without or outside of a transaction&amp;quot;, you will likely face problems in the future versions of NHibernate. Of course, there can be no data access outside of a transaction, be it read or write access, and NHibernate will make it much more difficult to write bad code that relies on auto-commit side effects. See section &amp;quot;Connection Release Modes&amp;quot; in the documentation for more details.&lt;/p&gt;
&lt;a name="A17"&gt;&lt;/a&gt;
&lt;h4&gt;Version numbers start with 1&lt;/h4&gt;
&lt;p&gt;The version property of a transient entity will be set to 1 when the entity is persisted (NHibernate 1.0 set the version number to 0). This was done to allow using a non-nullable type for the version property (such as&amp;nbsp;&lt;tt&gt;Int32&lt;/tt&gt;&amp;nbsp;or&amp;nbsp;&lt;tt&gt;Int64&lt;/tt&gt;), so that 0 could be used as&amp;nbsp;&lt;tt&gt;unsaved-value&lt;/tt&gt;&amp;nbsp;for the property.&lt;/p&gt;
&lt;a name="A18"&gt;&lt;/a&gt;
&lt;h4&gt;&lt;tt&gt;ISession.Get()&lt;/tt&gt;&amp;nbsp;will never return an unitialized proxy&lt;/h4&gt;
&lt;p&gt;Previously, calling&amp;nbsp;&lt;tt&gt;ISession.Get()&lt;/tt&gt;&amp;nbsp;could return an uninitialized proxy if the session contained the proxy as a result of some earlier operations. In NHibernate 1.2,&amp;nbsp;&lt;tt&gt;Get()&lt;/tt&gt;&amp;nbsp;will initialize the proxy in this case before returning it.&lt;/p&gt;
&lt;a name="A19"&gt;&lt;/a&gt;
&lt;h4&gt;&lt;tt&gt;ISession.Transaction&lt;/tt&gt;&amp;nbsp;is always active&lt;/h4&gt;
&lt;p&gt;&lt;tt&gt;ISession.Transaction&lt;/tt&gt;&amp;nbsp;property gives access to the current transaction associated with a session. Unlike previous NHibernate versions, as soon as this transaction is committed, a new transaction is associated with the session. Thus,&amp;nbsp;&lt;tt&gt;ISession.Transaction.WasCommitted&lt;/tt&gt;&amp;nbsp;and&amp;nbsp;&lt;tt&gt;WasRolledBack&lt;/tt&gt;&amp;nbsp;will always return&amp;nbsp;&lt;tt&gt;false&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;To be able to check the status of a particular transaction, assign it to a local variable:&lt;/p&gt;
&lt;pre class="code"&gt;ITransaction myTransaction = ISession.Transaction;
ISession.Transaction.Commit();
// ISession.Transaction.WasCommitted is false here,
// myTransaction.WasCommitted is true.
&lt;/pre&gt;
&lt;a name="A20"&gt;&lt;/a&gt;
&lt;h4&gt;Changes in ADO.NET provider assembly loading&lt;/h4&gt;
&lt;p&gt;NHibernate 1.2 now uses&amp;nbsp;&lt;tt&gt;Assembly.Load()&lt;/tt&gt;&amp;nbsp;instead of&amp;nbsp;&lt;tt&gt;Assembly.LoadWithPartialName()&lt;/tt&gt;&amp;nbsp;to load driver assemblies. This means that it will no longer look for the highest-versioned assembly in the Global Assembly Cache (GAC), which was sometimes undesirable. Instead, it is now your responsibility to either put the provider assembly into the application directory, or add a&amp;nbsp;&lt;tt&gt;qualifyAssembly&lt;/tt&gt;&amp;nbsp;element to the application configuration file, specifying the full name of the assembly.&lt;/p&gt;
&lt;p&gt;For example, if you are using MySQL Connector/.NET, you should either put&amp;nbsp;&lt;tt&gt;MySql.Data.dll&lt;/tt&gt;&amp;nbsp;into the application directory (or some other directory from where&lt;tt&gt;Assembly.Load()&lt;/tt&gt;&amp;nbsp;can pick it up), or put it in the GAC and add a&amp;nbsp;&lt;tt&gt;qualifyAssembly&lt;/tt&gt;&amp;nbsp;element to the configuration file:&lt;/p&gt;
&lt;pre class="code"&gt;&amp;lt;qualifyAssembly
    partialName=&amp;quot;MySql.Data&amp;quot;
    fullName=&amp;quot;MySql.Data, Version=..., PublicKeyToken=...&amp;quot;/&amp;gt;
&lt;/pre&gt;
&lt;a name="A21"&gt;&lt;/a&gt;
&lt;h3&gt;Query Language Changes&lt;/h3&gt;
&lt;a name="A22"&gt;&lt;/a&gt;
&lt;h4&gt;Changed aggregation (count, sum, avg) function return types&lt;/h4&gt;
&lt;p&gt;In alignment with Hibernate, the count, sum and avg functions now default to return types as specified by the JPA specification. This can result in&amp;nbsp;&lt;tt&gt;InvalidCastException&lt;/tt&gt;&amp;nbsp;&amp;#39;s at runtime if you used aggregation in HQL queries.&lt;/p&gt;
&lt;p&gt;The new type rules are as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;COUNT returns Int64.&lt;/li&gt;
&lt;li&gt;MAX, MIN return the type of the property to which they are applied.&lt;/li&gt;
&lt;li&gt;AVG returns Double.&lt;/li&gt;
&lt;li&gt;SUM returns Int64 when applied to properties of integral types; Double when applied to properties of floating point types; and Decimal when applied to state-fields of type Decimal.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you cannot change to the new type handling the following code can be used to provide &amp;quot;classic&amp;quot; NHibernate behavior for HQL aggregation.&lt;/p&gt;
&lt;pre class="code"&gt;  Configuration classicCfg = new Configuration(); 
  classicCfg.AddSqlFunction( &amp;quot;count&amp;quot;, new ClassicCountFunction()); 
  classicCfg.AddSqlFunction( &amp;quot;avg&amp;quot;, new ClassicAvgFunction()); 
  classicCfg.AddSqlFunction( &amp;quot;sum&amp;quot;, new ClassicSumFunction()); 
  ISessionFactory classicSf = classicCfg.BuildSessionFactory();
&lt;/pre&gt;
&lt;a name="A23"&gt;&lt;/a&gt;
&lt;h4&gt;Empty&amp;nbsp;&lt;tt&gt;Disjunction&lt;/tt&gt;&amp;nbsp;evaluates to false&lt;/h4&gt;
&lt;p&gt;A&amp;nbsp;&lt;tt&gt;Disjunction&lt;/tt&gt;&amp;nbsp;with no added conditions will always evaluate to false. This is a change from 1.0 and Hibernate, where an empty disjunction evaluates to true, but we feel it is more correct.&lt;/p&gt;
&lt;a name="A24"&gt;&lt;/a&gt;
&lt;h3&gt;Security-Related Changes&lt;/h3&gt;
&lt;a name="A25"&gt;&lt;/a&gt;
&lt;h4&gt;Strong name key is now public&lt;/h4&gt;
&lt;p&gt;NHibernate now uses a publicly available strong name key pair (&lt;tt&gt;NHibernate.snk&lt;/tt&gt;) to strong-name binary .NET assemblies. If you relied on the key being kept private for security, you should switch to other means of assuring assembly integrity, such as using a cryptographic hash.&lt;/p&gt;
&lt;p&gt;The original key pair used to sign NHibernate 1.0.x assemblies is still kept private.&lt;/p&gt;
&lt;a name="A26"&gt;&lt;/a&gt;
&lt;h4&gt;Assemblies are marked with AllowPartiallyTrustedCallersAttribute&lt;/h4&gt;
&lt;p&gt;Several assemblies have AllowPartiallyTrustedCallersAttribute (APTCA) applied to them, to make it easier to use NHibernate under Medium Trust Level. This attribute may potentially introduce security issues. To recompile NHibernate without APTCA, use this NAnt command:&lt;/p&gt;
&lt;pre class="code"&gt;nant -D:assembly.allow-partially-trusted-callers=false build&lt;/pre&gt;
&lt;/p&gt;</description></item></channel></rss>
