Hibernate的@Embeddable注解相当于XML映射文件? [英] Hibernate @embeddable annotation equivalent for XML mapping file?

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

问题描述

我有我创建一个Hibernate映射其中含有的旧对象,我不能修改类的,所以它不具备必要的id字段与Hibernate的发挥很好。我想诠释传统对象作为我的新类的@Embedded领域和写入遗留对象中的hbm.xml文件,并注意它是嵌入。有没有办法做到这一点?嵌入我见过对象的唯一文件是指注释对象,而不是使用XML。

I have a class that I am creating a Hibernate mapping which contains a legacy object that I can't modify, so it doesn't have the necessary id field to play nicely with Hibernate. I would like to annotate the legacy object as an @Embedded field of my new class and write an hbm.xml file for the legacy object and note that it is embeddable. Is there a way to do this? The only documentation for embedding objects I've seen refers to annotating objects instead of using XML.

我意识到,我可以扩展传统对象,并适当注释,但所以我想避免这种可能的话,这些情况可能会频繁发生。

I realize that I could extend the legacy object and annotate it appropriately, but these case might occur frequently so I'd like to avoid that if possible.

推荐答案

的XML对应 @Embedded &LT;成分&gt; ,见<一href=\"http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#mapping-declaration-component\">5.1.5.嵌入式对象(又名组件)。

The XML counterpart of @Embedded is <component>, see 5.1.5. Embedded objects (aka components).

但是,它不工作方式与 @Embeddable / @Embedded 一双一样的,你需要来描述的.hbm.xml 包含类的组件类的所有属性,是这样的:

However, it doesn't work the same way as the @Embeddable/@Embedded pair, you need to describe all properties of the component class in .hbm.xml of the containing class, something like this:

<class name = "NewClass">
    ...
    <component name = "legacyObject">
        ... properties of the legacy class ...
    </component>
</class>

这篇关于Hibernate的@Embeddable注解相当于XML映射文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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