5 Replies Latest reply on Jun 4, 2007 10:40 AM by Alex Savitsky

    fetchtype.LAZY results in JSF validation error

    Axel Roeber Newbie

      I found out that setting fetchtype.LAZY on a manyToOne association results in a JSF validation error for an selectOneMenu component.

      public OrgUnit getOrgUnit() {
      return orgUnit;

      <t:selectOneMenu id="orgunit" required="true" value="#{activity.orgUnit}" converter="orgunitconverter">
      <f:selectItems value="#{selectitemservice.orgUnitChoices}"/>

      public Object getAsObject(FacesContext context, UIComponent comp,
       String value) throws ConverterException {
       if (!StringUtils.isNumeric(value))
       return null ;
       Long id = Long.valueOf(value);
       Object object = em.find(OrgUnit.class, id);
       return object ;
      public String getAsString(FacesContext context, UIComponent component,
       Object object) throws ConverterException {
       if (object == null) {
       return null;
       if (object instanceof OrgUnit) {
       OrgUnit orgUnit = (OrgUnit)object ;
       String returnString = orgUnit.getId().toString();
       return returnString;
       return null ;

      The converter for OrgUnit seems to work: All units are displayed in the drop-down box and the current unit is also selected correctly in the box.
      But submitting a page with this component shows a validation error saying: "orgunit": Value is not a valid option.
      There are many things which could go wrong on my side but just removing the 'fetch=fetchtype.LAZY' (and therefore implicitly changing fetchtype to EAGER) results in a perfect working dialog. I suspect the use of a proxy for lazy fetching in Hibernate causing this, but debugging and tracing the converter and equals methods doesn't help me.

      Any ideas would be appreciated.