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.  [ 3 posts ] 
Author Message
 Post subject: A better way to map recurring patterns?
PostPosted: Sun Sep 16, 2007 2:57 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 4:08 pm
Posts: 28
I find a recurring issue comes up often in my NHibernate projects. What I'd really like is a way of defining a property, collection or mapping fragment in a single mapping file, then add a reference to it in each of the classes that segment applies to. It's an issue of having to change many mapping files if I make a single code change.

I could see this done a couple ways:

1) Most of the time, this common behavior happens in a class hierarchy where I have an abstract class that isn't mapped. For this, maybe something like an <unmapped-subclass> element that doesn't get mapped to a table would make sense. Where all properties in this mapping get deferred to child mapped classes?

2) For the case of unmapped interfaces, implemented by classes in completely different hierarchies, maybe create a new element in a mapping file for the definition of mapping segments, and provide a way to reference those definitions in mapped classes.

#1 would probably be the cleaner and easier to implement, but #2 is a little more flexible.

Definitions for #2 could look something like:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Eg" namespace="Eg" default-lazy="false">
  <mapping-def name="INotesContainer">
    <set name="Notes" cascade="save-update">
      <key column="ParentId" />
      <one-to-many class="Note"/>
    </set>
  </mapping-def>
</hibernate-mapping>


and references could look like:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Eg" namespace="Eg" default-lazy="false">
  <class name="SomeEntity" table="SomeEntities">
    <id name="Id">
      <generator class="guid.comb"/>
    </id>
    <mapping-ref name="INotesContainer"/>
  </class>
</hibernate-mapping>


Does this sound useful to anyone else? Is there a better way to do what I'm looking for? If I felt like contributing code for something like this, is there anyone I should talk to besides Sergey for feedback on design before getting started?

Thanks.


Last edited by jstelly on Sun Sep 16, 2007 6:46 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 16, 2007 6:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
This conversation is probably better to be continued on the NHibernate-development mailing list rather than in the user forum. I posted my reply to the list, please see here:

http://sourceforge.net/mailarchive/foru ... evelopment

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 16, 2007 11:49 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 4:08 pm
Posts: 28
Thanks Karl. I've joined the mailing list.

If a moderator wants to lock this topic to ensure all talk happens on the development mailing list, please do.


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