简体   繁体   中英

How would I map an @Entity with a hbm.xml?

I in a situation where I need to override some fields in a @Entity class but I can't edit the class. It just so happens that this @Entity class is mapped in a way that I don't think it's possible to partially override it. I was wondering what would be the steps to overriding this class completely or maybe partially if possible.

The class: org.broadleafcommerce.profile.core.domain.AddressImpl

I've used a hbm.xml and a orm.xml but I'm not exactly sure how to configure them properly.

The book Pro JPA 2 : Mastering the Java Persistence API notes:

The metadata-complete attribute is an attribute on the entity, mapped-superclass, and embeddable elements. If specified, all annotations on the specified class and on any fields or properties in the class will be ignored, and only the metadata in the mapping file will be considered as the set of metadata for the class. When metadata-complete is enabled, the same rules that we applied to annotated entities will still apply when using XML-mapped entities. For example, the identifier must be mapped, and all relationships must be specified with their corresponding cardinality mappings inside the entity element.

So you will need an entry in your orm.xml like the below, adding all other persistent attributes as required (partial override is not possible).

<entity-mappings>
    <entity class="com.Foo" metadata-complete="true">
        <table name="FOO"/>
        <attributes>
            <id name="id"/>
        </attributes>
    </entity>
</entity-mappings>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM