开发者

Hibernate @embeddable annotation equivalent for XML mapping file?

开发者 https://www.devze.com 2023-02-05 16:01 出处:网络
I have a class that I am creating a Hibernate mapp开发者_StackOverflow社区ing which contains a legacy object that I can\'t modify, so it doesn\'t have the necessary id field to play nicely with Hibern

I have a class that I am creating a Hibernate mapp开发者_StackOverflow社区ing 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.


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

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消