Hi, I have the following problem: I have a form object with a map of child field objects. The Map is of types <String, Field> where field is an abstract class and particular types of field subclass is and implement getValue(). The problem I have is that i need to be able to access the field values from the form index. The field name is stored in the index (fields.name) but not the values.
I would appreciate someone looking over these mappings.
Code:
@Entity
@Table(name="form")
@Indexed
public class Form implements Serializable, Cloneable , IFormsDataObject
{
......
private Map<String, Field> fields;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "form")
@MapKey(name = "name")
@Cascade({org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@IndexedEmbedded
public Map<String, Field> getFields() {
if(fields == null) fields = new HashMap<String, Field>();
return fields;
}
}
@Entity
@Table(name="field")
@Inheritance(strategy = InheritanceType.JOINED)
@Indexed
public abstract class Field implements Serializable, Cloneable {
private int id;
private String name;
//private String label;
private Form form;
@ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
@ContainedIn
public Form getForm() {
return form;
}
public void setForm(Form form) {
this.form = form;
}
@Id
@DocumentId
@GeneratedValue(strategy = GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@org.hibernate.search.annotations.Field(index= Index.TOKENIZED, store= Store.NO)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Transient
public abstract Class getValueClass();
public abstract void setValue(Object obj);
@Transient
public abstract Object getValue();
public Field clone() throws CloneNotSupportedException {
try {
Field f = this.getClass().newInstance();
f.setName(name);
f.setValue(this.getValue());
return f;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
@Entity
@Table(name="stringfield")
@Indexed
public class StringField extends Field implements Serializable {
private String value;
@org.hibernate.search.annotations.Field(index=Index.TOKENIZED, store= Store.NO)
public String getValue() {
return value;
}
@Transient
public Class getValueClass() {
return String.class;
}
public void setValue(Object obj) {
value = ((String) obj).trim();
}
public void setValue(String obj)
{
value = obj;
}
}