Hibernate映射:拆分文件 [英] Hibernate mappings: Splitting up the file

查看:88
本文介绍了Hibernate映射:拆分文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个简单的问题.我目前正在使用旧版数据库,因此不能做太多更改.数据库围绕单一类型即实体.所有其他相关数据(可自定义列表等除外)均从此继承".

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.

我正在使用一种联接的子类方法对此进行映射,效果很好.但是问题是我的映射文件达到了可怕的程度.我想将文件拆分为多个单独的文件,但是我不确定这是否可行以及如何解决此问题.我已经阅读了官方网站上的Hibernate文档,但找不到任何内容.

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)

推荐答案

我相信您可以使用扩展",例如:

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.

这篇关于Hibernate映射:拆分文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆