-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Java 5 enums and typedef
PostPosted: Thu Oct 26, 2006 11:29 pm 
Beginner
Beginner

Joined: Tue Aug 01, 2006 4:57 am
Posts: 25
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 3:49 pm 
Beginner
Beginner

Joined: Tue Aug 01, 2006 4:57 am
Posts: 25
is there a workaroudn???


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.