These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problems with immutable types/using default constructor
PostPosted: Tue Aug 12, 2008 4:37 am 
Newbie

Joined: Wed Jun 25, 2008 10:24 am
Posts: 3
Location: Ireland
Hi guys,

I am trying to push the integration of NHibernate into our codebase. The codebase is relatively new based on DDD, and we have abstracted the data domain layer behind interfaces. We are very ALT.NET influenced, using NUnit, RhinoMocks and Castle Windsor amongst other tools.

We recently had to choose an ORM, where I was pushing for NHibernate - but when I tried to integrate NHibernate I came across the following issues:

1. All entity types in our business domain are immutable, where each type has public readonly fields. I found the only way to map to these entities was by having private readonly fields with public get properties. Is there any way to directly map to entities with public readonly fields?

2. Even when I reverted to changing all entity types to the form of having private readonly fields with public get properties, I encountered another problem. In our coding standards, all private class level fields are of the form field.camelcase-c-underscore e.g. "c_fieldExample". Diving into NHibernate code, there is a PropertyAssessorFactory that contains all the different strategies but "field.camelcase-c-underscore" is not in there. It is quite easy to manually update the PropertyAssessorFactory and create a new CamelCaseCUnderscoreStrategy class, however is there a better way to do this. Is there a way to inject your own strategy?

3. Default constructor. I am forced to include a default constructor in all of my entity types. I read previously in Ayendes blog that a patch for fixing this issue. Is there any way of not having to include the default constructor?

Help would really be appreciated as we are currently using LINQ to SQL (temporary due to enforced deadline), which we want to swap out as soon as possible.


Top
 Profile  
 
 Post subject: Re: Problems with immutable types/using default constructor
PostPosted: Tue Aug 12, 2008 8:16 am 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
stacky wrote:
Hi guys,


3. Default constructor. I am forced to include a default constructor in all of my entity types. I read previously in Ayendes blog that a patch for fixing this issue. Is there any way of not having to include the default constructor?

Help would really be appreciated as we are currently using LINQ to SQL (temporary due to enforced deadline), which we want to swap out as soon as possible.
For the constructor issue: you can create a private default constructor on the entity types that do not have a default constructor, and for which you don't want to expose a public default constructor.

By making the default constructor private, consumers of your entities will not be able to construct an instance of that entity using the private constructor (it will not even be visible by intellisense i guess), but, since there is a default constructor (although it is private), NHibernate has the ability to use it. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.