Upgrade from nhibernate 3 to 4, iset code generation problem

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
kindbergs.dk
Posts: 13
Joined: Sun 27 Jan 2013 21:14

Upgrade from nhibernate 3 to 4, iset code generation problem

Post by kindbergs.dk » Thu 30 Jun 2016 22:29

Hi,
I have been using Entity Developer for NHibernate for a while, just got the latest version (6.0.20), and just upgraded a project to .NET 4.5.2 (started once upon a time as .net 3.5) and NHibernate 4 instead of 3.
When creating a new model, code gets generated with links as

Code: Select all

public virtual ISet<class> name
But an old model that has been in the solution for years (although different project/dll) generates links as

Code: Select all

public virtual Iesi.Collections.ISet name
- which does not compile.
Changeing the NHibernate template property "NHibernate V3 compatible" does not change the generated code (although file is rewritten).
Other projects which still are using NHibernate 3 get links as

Code: Select all

public virtual Iesi.Collections.Generic.ISet<class> name
which is correct NHibernate 3 syntax.

Any ideas as to what has gone wrong with code generation of this old model and how to fix it?
I think I read once regarding an Entity Developer update that templates had to be manually copied to existing projects, but which files from where to where?

kindbergs.dk
Posts: 13
Joined: Sun 27 Jan 2013 21:14

Re: Upgrade from nhibernate 3 to 4, iset code generation problem

Post by kindbergs.dk » Fri 01 Jul 2016 07:55

Found the template generator-thingy, and it smells like a bug:

Code: Select all

      case HibernateCollectionType.Set:
        if (relationProperty.Generic) {
          if (NHibernateV3Compatible)
            return string.Format("Iesi.Collections.Generic.ISet<{0}>", relationClassName);
          else
            return string.Format("ISet<{0}>", relationClassName);
        }
        else
          return "Iesi.Collections.ISet";
Basically, because the old model was not created with a Generic on as default, every single relation in the model had Generic set to off, and there is no NHibernateV3Compatible check on the bottom else, so the code does not compile...
Fixed it by opening the .hbml file in a text editor and doing a search/replace on generic="false" to generic="true", and after triggering Entity Developer to regenerate the code it then gives valid .net 4 and nhibernate 4 code.

Shalex
Site Admin
Posts: 8241
Joined: Thu 14 Aug 2008 12:44

Re: Upgrade from nhibernate 3 to 4, iset code generation problem

Post by Shalex » Mon 04 Jul 2016 15:08

Thank you for your detailed description of the issue. We will investigate the question and notify you about the result.

Shalex
Site Admin
Posts: 8241
Joined: Thu 14 Aug 2008 12:44

Re: Upgrade from nhibernate 3 to 4, iset code generation problem

Post by Shalex » Wed 06 Jul 2016 15:51

The behaviour of the predefined NHibernate template is fixed. We will notify you when the new build of Entity Developer is available for download.

Shalex
Site Admin
Posts: 8241
Joined: Thu 14 Aug 2008 12:44

Re: Upgrade from nhibernate 3 to 4, iset code generation problem

Post by Shalex » Thu 07 Jul 2016 16:58

The new (6.0.40) build of Entity Developer is available for download.

kindbergs.dk
Posts: 13
Joined: Sun 27 Jan 2013 21:14

Re: Upgrade from nhibernate 3 to 4, iset code generation problem

Post by kindbergs.dk » Tue 23 Aug 2016 20:11

Hi,
Thanks - the updated version seems to work for MS SQL Server without bothering about the generic attribute.
But for MySQL I found that while the code was generated correctly, doing an actual nhibernate query gave an exception

Code: Select all

"Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericSet`1[System.Object]' to type ..."
Suspecting the generic being the problem I went through the model and change all links with an old default of "false" to "true" and that fixed the runtime exception.

Shalex
Site Admin
Posts: 8241
Joined: Thu 14 Aug 2008 12:44

Re: Upgrade from nhibernate 3 to 4, iset code generation problem

Post by Shalex » Mon 29 Aug 2016 15:58

As we understood, the C# and mapping files generated by a predefined NHibernate template are correct. The issue was caused by missing "Generic=True" settings for relation properties in the *.hbml model, wasn't it?

kindbergs.dk
Posts: 13
Joined: Sun 27 Jan 2013 21:14

Re: Upgrade from nhibernate 3 to 4, iset code generation problem

Post by kindbergs.dk » Mon 29 Aug 2016 16:53

Yes, code seamed to be generated correct, but a runtime error occurred when selecting an object that had an iset<> with database linked objects from a MySQL database.
Purely as a guess: Is the generic property used anyplace else in the generated XMLs used by nhibernate to map objects to database tables?
Anyway, I think I got all my legacy projects converted now, so no longer an issue for me :-)

Post Reply