NH Bug and feature requests

Posts   
 
    
hardcodet
User
Posts: 6
Joined: 01-Oct-2011
# Posted on: 31-Oct-2011 15:30:26   

Hi all

FYI: The NH template creates a SessionManager that doesn't compile because there's a mixup with closing parentheses. I fixed the template a little, and also extended it with a partial configuration method that allows the user to add some further configs.

Furthermore, it would be nice to have support for the built-in proxy instead of Castle, LinFu and Spring (copy of the SessionManager I ended up with below).

It would be also nice if I could customize the cascading of updates. With the "Cascade All" being generated, I ended up with updates of an attached Employee entity just because I was updating and entity that was related to the employee.


static SessionManager()
{
    FluentConfiguration configuration = Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2005
                    .ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString.SQL Server (SqlClient)")))
        .ProxyFactoryFactory<DefaultProxyFactoryFactory>()              
        .Mappings(m => m.FluentMappings.AddFromAssembly(typeof(SessionManager).Assembly));
                
        ExtendConfiguration(configuration);
        _sessionFactory = configuration.BuildSessionFactory();
}
        
/// <summary>
/// Provides an extension point for customizations of the NHibernate
/// <see cref="configuration"/>.
/// </summary>
static partial void ExtendConfiguration(FluentConfiguration configuration);

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 31-Oct-2011 15:47:57   

Which Designer version (release date) are you using (Help->About)?

hardcodet
User
Posts: 6
Joined: 01-Oct-2011
# Posted on: 31-Oct-2011 16:39:59   

Walaa wrote:

Which Designer version (release date) are you using (Help->About)?

3.1 Final - TRIAL

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Nov-2011 04:22:48   

hardcodet wrote:

3.1 Final - TRIAL

What appears on "Released On" field on Help-About? The error you describe shouldn't happen, please download the latest installer and generate code again.

hardcodet wrote:

...and also extended it with a partial configuration method that allows the user to add some further configs.

To add additional settings to the SessionManager or to other mappings, see NH Additional Output Settings.

Also, if you want to extend the mappings for some mapping files, please see Extending the generated mapping files. For fluent you can add a partial class of the mapping file and implement the AdditionalMappingInfo method to add your additional mapping info.

hardcodet wrote:

Furthermore, it would be nice to have support for the built-in proxy instead of Castle, LinFu and Spring (copy of the SessionManager I ended up with below).

You can. Go to Project->Properties->Output Settings->BytecodeProxyFactory then set the proxy you want to use. This is described in Available Output Settings:

BytecodeProxyFactory. The bytecode proxy factory to use for the hibernate.cfg.xml file. The chosen proxy factory has to be referenced in the 'Persistence' VS.NET project which contains the hibernate.cfg.xml file generated. Default value: LinFu

hardcodet wrote:

It would be also nice if I could customize the cascading of updates. With the "Cascade All" being generated, I ended up with updates of an attached Employee entity just because I was updating and entity that was related to the employee.

Check the link I provided above (output settings) and find for "Cascade", you can set those settings so the generate code looks just like you want.

In case you don't find a setting for what you want, you can always Extend the generated mapping files.

So, normally you don't need to modify the built-in template files, as a matter of fact it's not recommended because you have to maintain your changes between updates. Almost every useful setting can be set through output setting values or by extending the generated files.

Now, if you need a setting in the Designer to generate a custom stuff and it isn't available you can write your own settings and generate your own custom templates. In general you won't reach this far, but just in case, you can take a look at the SDK documentation.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 01-Nov-2011 09:34:40   

Our automated build tests (generate code using a series of projects for the supported platforms, for VB/C#, compile them all) all succeed. Looking at the template, all parenthesis match... ->


//------------------------------------------------------------------------------
// <auto-generated>This code was generated by LLBLGen Pro v3.0.</auto-generated>
//------------------------------------------------------------------------------
using System;
using FluentNHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;

namespace NW
{
    /// <summary>Small, simple session manager class which initializes NHibernate's session factory and loads the configuration.</summary>
    public static partial class SessionManager
    {
        #region Class Member Declarations
        private static readonly ISessionFactory _sessionFactory;
        #endregion

        /// <summary>Initializes the <see cref="SessionManager"/> class.</summary>
        static SessionManager()
        {
            _sessionFactory = Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2005
                            .ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString.SQL Server (SqlClient)"))
                            .ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"))
                .Mappings(m => m.FluentMappings.AddFromAssembly(typeof(SessionManager).Assembly))
                .BuildSessionFactory();
        }

        /// <summary>Opens a new session on the existing session factory</summary>
        /// <returns>ready to use ISession instance</returns>
        /// <remarks>Dispose this instance after you're done with the instance, so after lazy loading has occured. The returned
        /// ISession instance is <b>not</b> thread safe.</remarks>
        public static ISession OpenSession()
        {
            return _sessionFactory.OpenSession();
        }

        #region Class Property Declarations
        /// <summary>Gets the session factory created from the initialized configuration. The returned factory is thread safe.</summary>
        public static ISessionFactory SessionFactory
        {
            get { return _sessionFactory; }
        }
        #endregion
    }
}

So I then looked at your class, and saw that you have .ProxyFactoryFactory as a method call on Configure(), not a method call on the value passed to .Database().

Is this necessary for the default factory factory in NH 3.2?

We haven't added code for supporting the default factory of NH3.2 yet, our release cycle is out of sync with NH's in this case: they added this in 3.2, correct? We'll look into adding support for the default proxy factory in v3.5, currently in development.

Frans Bouma | Lead developer LLBLGen Pro