Correct use of Access Strategies (NHibernate)

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
PeterM
Posts: 14
Joined: Tue 16 Jul 2013 12:53

Correct use of Access Strategies (NHibernate)

Post by PeterM » Tue 16 Jul 2013 13:22

Hi,

I'm wondering if someone can provide me with a concrete example of how to use the Access Strategies in Entity Developer correctly.
For simplicity I've just created a very simple model that contains an abstract Entity with only an Int64 Id and inherited from that an Person with a String Name.

I've just selected all the defaults with the exception of the Default Access property of the model. However No matter what I set that property to, the generated classes always get out the same. Classes are partials (which they shouldn't be either I think) and its properties are available as Property.

What I'd ultimately like is the possibility to set a ClassName as described here: http://nhforge.org/doc/nh/en/index.html#d0e3588
However, getting access strategies working at all would be nice :).
So, what am I doing wrong?

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

Re: Correct use of Access Strategies (NHibernate)

Post by Shalex » Thu 18 Jul 2013 07:18

PeterM wrote:However No matter what I set that property to, the generated classes always get out the same.
The generated classes should remain the same. The strategy used for accessing the property value is stored in the XML mapping (ModelName.ClassName.hbm.xml). For example:

Code: Select all

<hibernate-mapping assembly="ConsoleApplication211" namespace="ConsoleApplication211" xmlns="urn:nhibernate-mapping-2.2">
  <subclass name="Person" extends="Entity">
    <property name="Name" type="String" access="field.pascalcase-underscore">

PeterM
Posts: 14
Joined: Tue 16 Jul 2013 12:53

Re: Correct use of Access Strategies (NHibernate)

Post by PeterM » Thu 18 Jul 2013 09:36

Ok, I get the idea there.
However I do see some errors when using it in combination with Fluent and Repository and UoW.

Code: Select all

Could not find property nor field 'Id' in class 'PM4.Model.Entity'
During the creation of the sessionFactory. So I'm guessing that somewhere during generation an unforeseen dependency isn't handled correctly. Bluntly changing the Properties to Fields won't solve the problems since it will start complaining when creating relations (wrt proxies).

Am I also correct in noticing a different implementation related to these access strategies in the XML mapping and Fluent? When using Fluent it simply sets it to Field() which assumes that it can access a field named exactly as the name of the property. While the XML mapping mentions the naming strategy pascalcase-underscore.
For now I'll just continue without Fluent (which might be a bit less error-prone) but I do think it should either work out of the box or produce some pointers that certain combinations are unlikely to work without manual intervention.

PeterM
Posts: 14
Joined: Tue 16 Jul 2013 12:53

Re: Correct use of Access Strategies (NHibernate)

Post by PeterM » Thu 18 Jul 2013 11:19

A last (unrelated actually) remark wrt to my problems. Since I inherit everything from 'Entity' the primary key (Id) is defined only there. When creating relations it seems to have problems detecting that Id is not a good column to use for storing id's of related objects...

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

Re: Correct use of Access Strategies (NHibernate)

Post by Shalex » Fri 19 Jul 2013 17:03

PeterM wrote:When using Fluent it simply sets it to Field() which assumes that it can access a field named exactly as the name of the property. While the XML mapping mentions the naming strategy pascalcase-underscore.
We have reproduced the problem and will post here when it is fixed.
PeterM wrote:Could not find property nor field 'Id' in class 'PM4.Model.Entity'
PeterM wrote:When creating relations it seems to have problems detecting that Id is not a good column to use for storing id's of related objects
Are these problems the result of the pascalcase-underscore issue? If not, send us a test model and specify the steps we should follow for reproducing.

PeterM
Posts: 14
Joined: Tue 16 Jul 2013 12:53

Re: Correct use of Access Strategies (NHibernate)

Post by PeterM » Thu 25 Jul 2013 08:09

Sorry for the late reply, but the last mentioned problem about the Id is not directly related to the naming issue (I assume anyway). The first bit, 'Could not find...' is however!

For that last part, I'll send a model that produces that behavior.

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

Re: Correct use of Access Strategies (NHibernate)

Post by Shalex » Thu 25 Jul 2013 09:12

The bug with setting access strategy for the class property in fluent mapping is fixed. We will post here when the corresponding build of Entity Developer is available for donwload.

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

Re: Correct use of Access Strategies (NHibernate)

Post by Shalex » Thu 08 Aug 2013 15:20

New build of Entity Developer 5.5.164 is available for download now!
It can be downloaded from http://www.devart.com/entitydeveloper/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=32&t=27694.

Post Reply