-->
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.  [ 6 posts ] 
Author Message
 Post subject: Avoiding XML mapping files
PostPosted: Tue Nov 29, 2005 12:18 pm 
Of all the greatness in NHibernate, there is one aspect I find not so great; XML mapping files. I'd much prefer to do the mapping in code where it can be compiled, built, and tested with less trouble.

Looking at the Binder class, it seems like I could build up an equivalent PersistentClass and add it to the Mappings.

Does this seem reasonable? If so, are there any suggestions to go about doing it?


Top
  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 1:21 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
There are two attribute-based solutions. One is NHibernate.Mapping.Attributes in the NHibernateContrib package, and the other is Castle's ActiveRecord solution.


Top
 Profile  
 
 Post subject: Avoiding XML mapping files
PostPosted: Tue Nov 29, 2005 5:46 pm 
I've looked at attributes and active record. Both solutions force the POCOS to depend on NHibernate. I'd like to avaoid this too.

Building up the mappings in code, seperate from the POCOS, is what I'd really like.


Top
  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 7:54 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
NHibernate.Mapping.Attributes documentation wrote:
[...] NHibernate.Mapping.Attributes is not (really) intrusive. Setting attributes on your objects doesn't force you to use them with NHibernate and doesn't break any constraint on your architecture. Attributes are purely informative!


You have to add a reference to NHibernate.Mapping.Attributes.dll (not NHibernate.dll)!
And even if you had to add a reference to NHibernate.dll, conceptually, there will still be no usage of NHibernate.

Another "extreme" solution would be to have a separated set of class with attributes (so, you will have to maintain your domail model and update these "mapped classes" whenever your mapping change).

Anyway, do you have another possible solution for your issue?

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 1:50 pm 
Right. I understand that the attributes are unintrusive, but they still require a reference to the dll and using statement in all my POCOs. This is a violation of the Dependency Inversion Principle. It means I can't build without NHibernate or NHibernate.Mapping.Attributes. I'd like a DLL containing all my domain classes that has no external dependency.

I've considered the "extreme" solution and found it unpalatable. Using XML mapping files also provides the decoupling I want, it


Top
  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 6:56 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Anonymous wrote:
Right. I understand that the attributes are unintrusive, but they still require a reference to the dll and using statement in all my POCOs. This is a violation of the Dependency Inversion Principle. It means I can't build without NHibernate or NHibernate.Mapping.Attributes. I'd like a DLL containing all my domain classes that has no external dependency.


KPixel wrote:
You have to add a reference to NHibernate.Mapping.Attributes.dll (not NHibernate.dll)!


As far as I know, neither NMA or AR (or NHibernate for that matter) was explicitly designed using DI. Also, DI doesn't help when you need to use interfaces in the dependent assembly. DI is about object dependencies, not assembly dependencies. You could load objects by reflection, but attributes won't work that way.

If you want an attribute-based mapping solution that you don't have to write yourself, you have to reference an external dll of some kind. Otherwise, you have to do the mapping yourself. I know of no other solution.

Seems like a very expensive requirement. What is the reason for it? License issues?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.