Page 1 of 1

Problem with NHibernate custom type

Posted: Mon 30 May 2016 20:02
by Joe Smith
Hi,

I managed to implement an automatic encrypted field in my NHibernate mapping project following this snippet: https://gist.github.com/jfromaniello/1941179
I added a custom type def in ED named "Encrypted", and assigned it to the property I want to store in encrypted format ("SmtpPassword") through the "User Converter Type" in the Properties window, because I need the type of the class property to remains a string.
Yuo can refer also to http://nhibernate.info/blog/2009/02/21/ ... rnate.html

The generated code was:

"MyProjectName.hbm.xml":

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping schema="dbo" assembly="MyAssemblyName" namespace="MyNameSpace" xmlns="urn:nhibernate-mapping-2.2">
  <typedef name="Encrypted" class="MyNameSpace.EncryptedString, MyAssemblyName">
    <param name="encryptor">MyNameSpace.AESEncryptor, MyAssemblyName</param>
    <param name="encryptionKey">my_strong_password</param>
  </typedef>
</hibernate-mapping>
MyClass.hbm.xml:

Code: Select all

<property name="SmtpPassword" type="Encrypted">
  <column name="SmtpPassword" not-null="false" length="100" sql-type="NVARCHAR(100)" />
</property>
The code generated is correct and does reflect those of the code snippet in the above link but if I leave the typedef in the separate files that ED generates (and which I have added to my solution as an "embedded resource") I got the following error when I run my app:
"Could not determine type for: MyNameSpace.EncryptedString, MyAssemblyName, for columns: NHibernate.Mapping.Column(SmtpPassword)"
If I move the typedef node in MyClass.hbm.xml file, immediately before the "class" node, it works perfectly.

Is this a bug or I'm missing something?
I'm using ED version 5.8.846

Please note: I don't want to specify the class full qualifier name in the "type" property of the "SmtpPassword" field because in this way I can't make use of the additional parameters defined in typedef.
Thank you.

Re: Problem with NHibernate custom type

Posted: Fri 03 Jun 2016 16:15
by Shalex
This question exceeds the goals of our support. You should contact the NHibernate team to find out the reason why NHibernate runtime doesn't concatenate your MyProjectName.hbm.xml with other *.hbm.xml files within your project.

We think that the issue can be caused by different values of the assembly and namespace attributes in MyProjectName.hbm.xml (comparing to the ones in MyClass.hbm.xml and other *.hbm.xml files).

Re: Problem with NHibernate custom type

Posted: Mon 06 Jun 2016 20:03
by Joe Smith
After having done many tests and researches, in particular on the NHibernate group (for example, see
https://groups.google.com/forum/#!searc ... ZWmtKqYA8J), I also do belive this is a NHibernate bug, but I think they'll never going to fix it.

The most practical solution I can think of is that ED should generate the type definition in the same mapping file of the class that uses it, because this is really the only way it works.

Re: Problem with NHibernate custom type

Posted: Tue 07 Jun 2016 11:40
by Shalex
Entity Developer doesn't support the type definitions (typedef) at the moment. Please submit your feature request at https://devart.uservoice.com/forums/386 ... -developer.

Re: Problem with NHibernate custom type

Posted: Tue 07 Jun 2016 17:15
by Joe Smith
Shalex wrote:Entity Developer doesn't support the type definitions (typedef) at the moment. Please submit your feature request at https://devart.uservoice.com/forums/386 ... -developer.
I'm very confused now because I used ED to generate my typedef :shock:
It's right in the model properties, the last option under "General" section, "Type Defs"

Re: Problem with NHibernate custom type

Posted: Wed 08 Jun 2016 08:26
by Shalex
Joe Smith wrote:I'm very confused now because I used ED to generate my typedef :shock:
It's right in the model properties, the last option under "General" section, "Type Defs"
You are right, my mistake. Entity Developer supports Type Defs.
Joe Smith wrote:ED should generate the type definition in the same mapping file of the class that uses it, because this is really the only way it works.
Please select the NHibernate template in Model Explorer and set its Xml Mapping File Per Class property to False to place all mapping into a single file.

Re: Problem with NHibernate custom type

Posted: Wed 08 Jun 2016 17:06
by Joe Smith
Shalex wrote:Please select the NHibernate template in Model Explorer and set its Xml Mapping File Per Class property to False to place all mapping into a single file.
To be honest, I don't really like this solution. The "file-per-class" option seems much more practical and manageable approach to me. Also, are initial NH startup performance affected with one big XML mapping file? I need to do more research before making a decision.
Thanks anyway.

Re: Problem with NHibernate custom type

Posted: Mon 13 Jun 2016 18:04
by Shalex
The behaviour is changed: the type definitions (typedef) are generated now in XML mapping files of each class, which uses the typedefs, if the Xml Mapping File Per Class template property is set to True. We will notify you when the corresponding build of Entity Developer is available for download.

Re: Problem with NHibernate custom type

Posted: Thu 23 Jun 2016 16:10
by Shalex
The new build of Entity Developer 6.0.30 is available for download now: viewtopic.php?f=32&t=33852.

Re: Problem with NHibernate custom type

Posted: Fri 24 Jun 2016 13:47
by Joe Smith
Shalex wrote:The new build of Entity Developer 6.0.30 is available for download now: viewtopic.php?f=32&t=33852.
Unfortunately, the problem is still there, probably because the program relies upon the "Type" property of the field whereas I use the "User Converter Type" instead in order to preserve the original member type ("String", in this case)

Re: Problem with NHibernate custom type

Posted: Thu 30 Jun 2016 16:37
by Shalex
We will investigate the question and notify you about the result.

Re: Problem with NHibernate custom type

Posted: Thu 07 Jul 2016 17:16
by Shalex
Joe Smith wrote:Unfortunately, the problem is still there, probably because the program relies upon the "Type" property of the field whereas I use the "User Converter Type" instead in order to preserve the original member type ("String", in this case)
The issue should be fixed in the newest (6.0.40) build of Entity Developer. Please try it and notify us about the result.

Re: Problem with NHibernate custom type

Posted: Fri 08 Jul 2016 15:21
by Joe Smith
Shalex wrote:
Joe Smith wrote:Unfortunately, the problem is still there, probably because the program relies upon the "Type" property of the field whereas I use the "User Converter Type" instead in order to preserve the original member type ("String", in this case)
The issue should be fixed in the newest (6.0.40) build of Entity Developer. Please try it and notify us about the result.
Ok, now it works :wink: