Page 1 of 1
Upgrade from nhibernate 3 to 4, iset code generation problem
Posted: Thu 30 Jun 2016 22:29
by kindbergs.dk
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
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?
Re: Upgrade from nhibernate 3 to 4, iset code generation problem
Posted: Fri 01 Jul 2016 07:55
by kindbergs.dk
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.
Re: Upgrade from nhibernate 3 to 4, iset code generation problem
Posted: Mon 04 Jul 2016 15:08
by Shalex
Thank you for your detailed description of the issue. We will investigate the question and notify you about the result.
Re: Upgrade from nhibernate 3 to 4, iset code generation problem
Posted: Wed 06 Jul 2016 15:51
by Shalex
The behaviour of the predefined NHibernate template is fixed. We will notify you when the new build of Entity Developer is available for download.
Re: Upgrade from nhibernate 3 to 4, iset code generation problem
Posted: Thu 07 Jul 2016 16:58
by Shalex
The new (6.0.40) build of Entity Developer is available for download.
Re: Upgrade from nhibernate 3 to 4, iset code generation problem
Posted: Tue 23 Aug 2016 20:11
by kindbergs.dk
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.
Re: Upgrade from nhibernate 3 to 4, iset code generation problem
Posted: Mon 29 Aug 2016 15:58
by Shalex
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?
Re: Upgrade from nhibernate 3 to 4, iset code generation problem
Posted: Mon 29 Aug 2016 16:53
by kindbergs.dk
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
