Hi
After going through the online documentation for how to map enum property of a java object to hibernate this is what I have done:
in the hbm file I have
Code:
<typedef name="destinationEnumType" class='net.hoike.bluetropics.simulator.types.enumtypes.EnumUserType'>
<param name="enumClassName">net.hoike.bluetropics.simulator.types.DestinationType</param>
</typedef>
Now, I am using MySQL... at present the datatype for the variable is varchar... My first question is what should be its datatype in MySQL?
The other thing... I am using these in a webapplication to populate the values of drop-dwon box and am using Spring framework. I have writeen property editors for every enum and one of them is as shown below:
Code:
public class DestinationTypeEditor extends PropertyEditorSupport{
private DestinationType destType = null;
public DestinationTypeEditor(){}
public Object getValue(){
return destType;
}
public void setValue(Object destType)
{
if(((DestinationType) destType) == DestinationType.HTTP){
destType = DestinationType.HTTP;
}else if(((DestinationType) destType) == DestinationType.JMS){
destType = DestinationType.JMS;
}
}
public String getAsText(){
if(destType == DestinationType.HTTP){
return "HTTP";
}
else
return "JMS";
}
public void setAsText(String val) throws IllegalArgumentException{
if(val.equalsIgnoreCase("HTTP")){
destType = DestinationType.HTTP;
setValue(destType);
}
else if(val.equalsIgnoreCase("JMS")){
destType = DestinationType.JMS;
setValue(destType);
}
else{
throw new IllegalArgumentException();
}
}
}
I register this enum in the SimpleFormcontroller as below:
Code:
binder.registerCustomEditor(DestinationType.class,new DestinationTypeEditor());
In the JSP, I am binding the properties like this:
Code:
<spring:bind path="simulationForm.simulation.destinationType">
<select name="<c:out value="${status.expression}"/>">
<c:forEach items="${destinationType}" var="destType">
<option value="${destType}" <c:if test="${status.value == destType}">selected="selected"</c:if>>
<spring:message code="destinationType.${destType}"/></option>
</c:forEach>
</select>
</spring:bind>
I can initially see the form properly but when I select the values and submit the form... everything gets stored but not the enum values. and after the submission all the f\drop down values disappear... I dont know what is going on? can someone help me with why the Hibernate is unable to persist the data?
Please help... this is important... If I am not clear anywhere or if I am missing something just let me know so that I can clarify more.