我如何将 @Entity 映射到 hbm.xml?
How would I map an @Entity with a hbm.xml?
我需要覆盖@Entity class 中的某些字段,但我无法编辑 class。碰巧这个@Entity class 的映射方式我认为不可能部分覆盖它。我想知道完全或可能部分覆盖此 class 的步骤是什么。
class:
org.broadleafcommerce.profile.core.domain.AddressImpl
我使用了 hbm.xml 和 orm.xml,但我不确定如何正确配置它们。
本书 Pro JPA 2:掌握 Java 持久性 API 注释:
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.
因此您需要在 orm.xml 中添加一个条目,如下所示,根据需要添加 所有 其他持久属性(无法部分覆盖)。
<entity-mappings>
<entity class="com.Foo" metadata-complete="true">
<table name="FOO"/>
<attributes>
<id name="id"/>
</attributes>
</entity>
</entity-mappings>
我需要覆盖@Entity class 中的某些字段,但我无法编辑 class。碰巧这个@Entity class 的映射方式我认为不可能部分覆盖它。我想知道完全或可能部分覆盖此 class 的步骤是什么。
class: org.broadleafcommerce.profile.core.domain.AddressImpl
我使用了 hbm.xml 和 orm.xml,但我不确定如何正确配置它们。
本书 Pro JPA 2:掌握 Java 持久性 API 注释:
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.
因此您需要在 orm.xml 中添加一个条目,如下所示,根据需要添加 所有 其他持久属性(无法部分覆盖)。
<entity-mappings>
<entity class="com.Foo" metadata-complete="true">
<table name="FOO"/>
<attributes>
<id name="id"/>
</attributes>
</entity>
</entity-mappings>