views:

47

answers:

1

Alright, I've got a quick question. I'm currently working with a legacy database, so I can't change around much. The database revolves around a single type, the entity. All other relevant data (except for customizable lists etc.) 'inherit' from this.

I'm mapping this with a joined subclass approach, which is working fine. The problem however, is that my mapping file is reaching hideous proportions. I would like to split up the file in multiple separate files, but I'm not sure if this is possible and how to approach this problem. I've read through the Hibernate docs on the official site, but couldn't find anything.

To clarify, mappings look like this:

<class name="..." table="...">
    <id ...>
            <generator class="org.hibernate.id.TableHiLoGenerator">
                    <param name="table">...</param>
                    <param name="column">...</param>
            </generator>
    </id>
    <property name="somethingCommon" />
    <joined-subclass name="class_1">
     ...
     ...
    </joined-subclass>
    <joined-subclass name="class_2">
     ...
     ...
    </joined-subclass>
    ...
    <joined-subclass name="class_n">
     ...
     ...
    </joined-subclass>
</class>

What I would like to be able to do is put the joined-subclass bits in separate files, just like I would do in code (separate classes -> separate files). Is this possible using just mappings, or perhaps by manipulating the mappings when I load them?

(Note: tagged hibernate/nhibernate, as I don't think this is specific to either flavor)

+3  A: 

I believe you can use "extends" eg:

<hibernate-mapping>
 <joined-subclass name="DomesticCat" extends="Cat">
      ...
 </joined-subclass>

to separate out the joined subclasses into separate files.

Michael Gattuso
Yes, that's it! Thanks, this was one of the last annoyances in the project.
Erik van Brakel