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: Mapping preferences: Attributes vs. Xml
PostPosted: Wed Aug 02, 2006 2:27 pm 
Beginner
Beginner

Joined: Wed Apr 19, 2006 9:16 am
Posts: 24
Hi all,

I've been using NHibernate for a about 3 to 4 months now, and am absolutely positive that it's the persistence layer to use (at least, for me (and my company)).

One thing still keeps nagging though: Should I use attributes or just plain xml to map the domain?

Personally, I've developed a preference for mapping with attributes and used the generated xml as a second source of information to find out why a mapping didn't work (i.e.: what I did wrong).

Attributes introduce the notion of persistence to the domainlibrary.
On the upside, I think it makes developers aware of persistence and reminds them that it's not magic at work but a persistencelayer, and simultaneously (hopefully) alerts them to pay attention to *what* they change and the consequences it may have. On the down side, well, it introduces persistenceinformation in the domainlibrary ;)

I'm happy (and curious) to hear about everyone's opinion on this issue.

_________________
regards,
Willem van Rumpt


Top
 Profile  
 
 Post subject: Re: Mapping preferences: Attributes vs. Xml
PostPosted: Wed Aug 02, 2006 2:37 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Willem van Rumpt wrote:
I'm happy (and curious) to hear about everyone's opinion on this issue.

At the moment I use NHibernate for the pet project only.
I have chosen to use Attributes also. My main reason was, that I did not want to maintain two versions of class structure (mapping and code files). Also, it makes typos less frequent.

The only (propable) difference is that I did write my own hbm writer, and my own set of attributes. Reason: I want the hbm to be generated in quite restricted way (I would propably never use comnposite id, for example), so I can leave out many details from attributes - they are defined implicitly.

Just my .02$

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject: Re: Mapping preferences: Attributes vs. Xml
PostPosted: Wed Aug 02, 2006 2:49 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I see NHibernate attributes more like documentation; they do not affect the behavior of the entities; so I also prefer this way.

gert wrote:
The only (propable) difference is that I did write my own hbm writer, and my own set of attributes. Reason: I want the hbm to be generated in quite restricted way (I would propably never use comnposite id, for example), so I can leave out many details from attributes - they are defined implicitly.


This is interesting. Can you give more details about that?
Do you see some places where NHibernate.Mapping.Attributes can be improved to better support your "restricted way"?

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 2:52 pm 
Beginner
Beginner

Joined: Wed Apr 19, 2006 9:16 am
Posts: 24
Quote:
My main reason was, that I did not want to maintain two versions of class structure (mapping and code files)


That is another benefit indeed. One source that rules all, if you will :)

Quote:
The only (propable) difference is that I did write my own hbm writer, and my own set of attributes. Reason: I want the hbm to be generated in quite restricted way (I would propably never use comnposite id, for example), so I can leave out many details from attributes - they are defined implicitly.


I've thought about writing one from scratch (accompanying attributes included), but voted against it for the moment. Partly because we've got legacy databases that do use such features, but, to be honest, mostly because I simply lack the time ;)

_________________
regards,
Willem van Rumpt


Top
 Profile  
 
 Post subject: Re: Mapping preferences: Attributes vs. Xml
PostPosted: Wed Aug 02, 2006 2:58 pm 
Beginner
Beginner

Joined: Wed Apr 19, 2006 9:16 am
Posts: 24
KPixel wrote:
I see NHibernate attributes more like documentation; they do not affect the behavior of the entities; so I also prefer this way.


Indeed. I think it translates my thoughts better than my own rambling in the original post. Developers can focus on classdesign and implementation, while still keeping an eye on the infrastructure already there.

_________________
regards,
Willem van Rumpt


Top
 Profile  
 
 Post subject: Re: Mapping preferences: Attributes vs. Xml
PostPosted: Wed Aug 02, 2006 4:03 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
KPixel wrote:
This is interesting. Can you give more details about that?

Well, for example, I have decided that by default, all proeprties of persistent class are stored. If I want a property to be non-stored, I add attribute for that.
Also, all my classes use same equally named ObjectId and version properties, so I do not need define those with attributes.
Third, I always use nosetter.pascalcase-m-underscore as access modifier, so it is hardcoded into hbm writer.
And lazy loading.

Also, I have decided quite certain way to define collections, so my typical IList looks like

Code:
    [InverseRelation("Parent", RelationType = RelationType.Bag)]
    public virtual IList<SubItem> SubItems


So, most of the "improvements" are depending on my coding style, and not usable for general audience. But they help me to keep code files a bit cleaner..

KPixel wrote:
Do you see some places where NHibernate.Mapping.Attributes can be improved to better support your "restricted way"?


I haven't analyzed what and how the NHibernate.Mapping.Attributes provides. I looked at them briefly when I started using NHibernate (version 0.9.x I think), but decided that they required too much details that were constant in my implementation.

Gert

_________________
If a reply helps You, rate it!


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.