hibernate动态组件等效注解

Mor*_*ndi 5 java annotations hibernate dynamic hibernate-mapping

在 hibernate 中通过注释定义动态组件的等效方法是什么?

public abstract class CustomizableEntity {

 private Map customProperties;

 public Map getCustomProperties() {
         if (customProperties == null)
             customProperties = new HashMap();
        return customProperties;
 }
 public void setCustomProperties(Map customProperties) {
        this.customProperties = customProperties;
 }

 public Object getValueOfCustomField(String name) {
     return getCustomProperties().get(name);
 }

 public void setValueOfCustomField(String name, Object value) {
     getCustomProperties().put(name, value);
 }

 }
Run Code Online (Sandbox Code Playgroud)

我的实体:

public class Contact extends CustomizableEntity {

 private int id;
 private String name;

 public int getId() {
     return id;
 }

 public void setId(int id) {
     this.id = id;
 }

 public String getName() {
     return name;
 }

 public void setName(String name) {
     this.name = name;
 }

 }
Run Code Online (Sandbox Code Playgroud)

休眠 XML:

<hibernate-mapping auto-import="true" default-access="property" default-cascade="none" default-lazy="true">

 <class abstract="false" name="com.enterra.customfieldsdemo.domain.Contact" table="tbl_contact">

     <id column="fld_id" name="id">
         <generator class="native"/>
     </id>

     <property name="name" column="fld_name" type="string"/>
     <dynamic-component insert="true" name="customProperties" optimistic-lock="true" unique="false" update="true">
     </dynamic-component>
 </class>
 </hibernate-mapping> 
Run Code Online (Sandbox Code Playgroud)

我想使用 HashMap 的动态组件在运行时创建实体。在 hibernate 中通过注释定义动态组件的等效方法是什么? http://www.infoq.com/articles/hibernate-custom-fields