5

What is the equivalent way of defining dynamic component in hibernate by annotations?

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);
 }

 }

my entity:

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;
 }

 }

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

I want to use a dynamic-component by HashMap to create entities at runtime. What is the equivalent way of defining dynamic component in hibernate by annotations? http://www.infoq.com/articles/hibernate-custom-fields

Morteza Malvandi
  • 1,656
  • 7
  • 30
  • 73

0 Answers0