Problem with NHibernate custom type

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
Joe Smith
Posts: 32
Joined: Thu 09 May 2013 20:18

Problem with NHibernate custom type

Post by Joe Smith » Mon 30 May 2016 20:02

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.

Shalex
Devart Team
Posts: 8034
Joined: Thu 14 Aug 2008 12:44

Re: Problem with NHibernate custom type

Post by Shalex » Fri 03 Jun 2016 16:15

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).

Joe Smith
Posts: 32
Joined: Thu 09 May 2013 20:18

Re: Problem with NHibernate custom type

Post by Joe Smith » Mon 06 Jun 2016 20:03

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.

Shalex
Devart Team
Posts: 8034
Joined: Thu 14 Aug 2008 12:44

Re: Problem with NHibernate custom type

Post by Shalex » Tue 07 Jun 2016 11:40

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.

Joe Smith
Posts: 32
Joined: Thu 09 May 2013 20:18

Re: Problem with NHibernate custom type

Post by Joe Smith » Tue 07 Jun 2016 17:15

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"

Shalex
Devart Team
Posts: 8034
Joined: Thu 14 Aug 2008 12:44

Re: Problem with NHibernate custom type

Post by Shalex » Wed 08 Jun 2016 08:26

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.

Joe Smith
Posts: 32
Joined: Thu 09 May 2013 20:18

Re: Problem with NHibernate custom type

Post by Joe Smith » Wed 08 Jun 2016 17:06

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.

Shalex
Devart Team
Posts: 8034
Joined: Thu 14 Aug 2008 12:44

Re: Problem with NHibernate custom type

Post by Shalex » Mon 13 Jun 2016 18:04

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.

Shalex
Devart Team
Posts: 8034
Joined: Thu 14 Aug 2008 12:44

Re: Problem with NHibernate custom type

Post by Shalex » Thu 23 Jun 2016 16:10

The new build of Entity Developer 6.0.30 is available for download now: viewtopic.php?f=32&t=33852.

Joe Smith
Posts: 32
Joined: Thu 09 May 2013 20:18

Re: Problem with NHibernate custom type

Post by Joe Smith » Fri 24 Jun 2016 13:47

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)

Shalex
Devart Team
Posts: 8034
Joined: Thu 14 Aug 2008 12:44

Re: Problem with NHibernate custom type

Post by Shalex » Thu 30 Jun 2016 16:37

We will investigate the question and notify you about the result.

Shalex
Devart Team
Posts: 8034
Joined: Thu 14 Aug 2008 12:44

Re: Problem with NHibernate custom type

Post by Shalex » Thu 07 Jul 2016 17:16

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.

Joe Smith
Posts: 32
Joined: Thu 09 May 2013 20:18

Re: Problem with NHibernate custom type

Post by Joe Smith » Fri 08 Jul 2016 15:21

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:

Post Reply