title: Caused by: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
body: <p>I have a form from my entity (weatherstation) .
  I also have a field called "bezeichnung" (description). When i enter a string and i press the  search button (for searching) i always get an Exception:</p>
  
  <blockquote>
    <p>Caused by: java.lang.ArrayIndexOutOfBoundsException: Array index out
    of range: 0</p>
  </blockquote>
  
  <p>In my database is one object with the bezeichnung "Traunstein"</p>
  
  <p>Entity (with getter and setter):</p>
  
  <pre><code>@Entity
  @NamedQuery(name="findbybez", query="select w from Weterstation w where w.bezeichnung like :bez")
  public class Weterstation implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      @Column(nullable=false, unique=true)
      @Length(min=3, max=20, message="Min.-&gt;3 Max-&gt;20")
      private String bezeichnung;
  
      @Column(nullable=false)
      @Pattern(regexp="[0-9][0-9][0-9][0-9]" , message="PLZ ist falsch")
      private String plz;
  
      @Column(nullable=false)
      @Length(min=3, max=20, message="Min.-&gt;3 Max-&gt;20")
      @Pattern(regexp="^[A-Z][a-z]*", message="Der Ort muss einen Anfangsbuchstaben machen")
      private String ort;
  
      @Column(nullable=false)
      @TempValid(message="Min -40°C, Max 40°C")
      private double temp;
  
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  </code></pre>
  
  <p>Facade Methode:</p>
  
  <pre><code>@Override
      public Weterstation findbyBezeichnung(String name) {
        List e =  em.createNamedQuery("findbybez").setParameter("bez", name).getResultList();
        Weterstation w = new Weterstation();
        if(e.get(0)!=null)
        {
            w = (Weterstation)e.get(0);
        }
          return w;
      }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;f:view&gt;
                  &lt;h:form&gt;
                      &lt;h1&gt;&lt;h:outputText value="Create/Edit"/&gt;&lt;/h1&gt;
                      &lt;h:panelGrid columns="3"&gt;
                          &lt;h:outputLabel value="Id:" for="id" /&gt;
                          &lt;h:inputText id="id" value="#{wettercontroller.station.id}" title="Id" disabled="true"/&gt;
                          &lt;h:message for="id"&gt;&lt;/h:message&gt;
                          &lt;h:outputLabel value="Bezeichnung:" for="bezeichnung" /&gt;
                          &lt;h:inputText id="bezeichnung" value="#{wettercontroller.station.bezeichnung}" title="Bezeichnung" required="true" requiredMessage="The Bezeichnung field is required."/&gt;
                          &lt;h:message for="bezeichnung"&gt;&lt;/h:message&gt;
                          &lt;h:outputLabel value="Ort:" for="ort" /&gt;
                          &lt;h:inputText id="ort" value="#{wettercontroller.station.ort}" title="Ort" required="true" requiredMessage="The Ort field is required."/&gt;
                          &lt;h:message for="ort"&gt;&lt;/h:message&gt;
                          &lt;h:outputLabel value="Plz:" for="plz" /&gt;
                          &lt;h:inputText id="plz" value="#{wettercontroller.station.plz}" title="Plz" required="true" requiredMessage="The Plz field is required."/&gt;
                          &lt;h:message for="plz"&gt;&lt;/h:message&gt;
                          &lt;h:outputLabel value="Temp:" for="temp" /&gt;
                          &lt;h:inputText id="temp" value="#{wettercontroller.station.temp}" title="Temp" required="true" requiredMessage="The Temp field is required."/&gt;
                          &lt;h:message for="temp" &gt;&lt;/h:message&gt;
  
                      &lt;/h:panelGrid&gt;
                      &lt;h:commandButton value="Create" action="#{wettercontroller.createWetter()}"&gt;&lt;/h:commandButton&gt;
                      &lt;h:commandButton value="SearchBez" action="#{wettercontroller.searchbez()}" immediate="true" &gt;&lt;/h:commandButton&gt;
                  &lt;/h:form&gt;
              &lt;/f:view&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>@ManagedBean
  @SessionScoped
  public class Wettercontroller implements Serializable {
  
      @EJB
      WeterstationFacadeLocal wetterfacade;
  
      private Weterstation station;
  
      private long id;
  
  
  
  
  
      /** Creates a new instance of Wettercontroller */
      public Wettercontroller() {
          station = new Weterstation();
      }
          public void searchbez()
      {
          station = wetterfacade.findbyBezeichnung(station.getBezeichnung());
      }
  </code></pre>
  
  <p>In the debugg-mode i see in the <code>searchbez()</code> that the "bezeichnung" is null.
  I have to use the <code>immediate="true"</code> that the other elements will not be parsed
  Please Help</p>