title: JSF/JPA error: The class 'java.lang.String' does not have the property
body: <p>I'm displaying a list of Football Players from a database, which the user can select, and add to an ArrayList. Displaying all players works fine, but not for the selected ones. When I ask for the plain object or its hashcode, its returns its, but as soon as I reference a property pertaining to the Player entity, it gives an error.  Anyone?</p>
  
  <p><strong>Backing bean</strong></p>
  
  <pre><code>@Named
  @SessionScoped
  public class PlayerBean implements Serializable {
  
  private static final long serializableUID = 1L;
  @Inject
  PlayerFacade facade;
  
  private List&lt;Player&gt; allPlayers;
  private List&lt;Player&gt; selectedPlayers;
  
  public PlayerBean() {
  }
  
  public List&lt;Player&gt; getAllPlayers() {
      return facade.findAll();
  }
  
  
  public List&lt;Player&gt; getSelectedPlayers() {
      return selectedPlayers;
  }
  
  public void setSelectedPlayers(List&lt;Player&gt; selectedPlayers) {
      this.selectedPlayers= selectedPlayers;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Entity Class</strong></p>
  
  <pre><code>@Entity
  @Table(name = "player")
  @XmlRootElement
  
  public class Player implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Basic(optional = false)
  @Column(name = "PlayerID")
  private Integer playerID;
  @Size(max = 45)
  @Column(name = "Name")
  private String name;
  @Size(max = 45)
  @Column(name = "Position")
  private String position;
  // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
  @Column(name = "Weight")
  private BigDecimal weight;
  
  public Player() {
  }
  
  public Player(Integer playerID) {
      this.playerID = playerID;
  }
  
  public Integer getPlayerID() {
      return playerID;
  }
  
  public void setPlayerID(Integer playerID) {
      this.playerID = playerID;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getPosition() {
      return position;
  }
  
  public void setPosition(String position) {
      this.position = position;
  }
  
  public BigDecimal getWeight() {
      return weight;
  }
  
  public void setWeight(BigDecimal weight) {
      this.weight = weight;
  }
  
  @Override
  public int hashCode() {
      int hash = 0;
      hash += (playerID != null ? playerID.hashCode() : 0);
      return hash;
  }
  
  @Override
  public boolean equals(Object object) {
      // TODO: Warning - this method won't work in the case the id fields are not set
      if (!(object instanceof Player)) {
          return false;
      }
      Player other = (Player) object;
      if ((this.playerID == null &amp;&amp; other.playerID != null) || (this.playerID != null &amp;&amp; !this.playerID.equals(other.playerID))) {
          return false;
      }
      return true;
  }
  
  @Override
  public String toString() {
      return "playerID=" + playerID + " ]";
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>JSF Page</strong></p>
  
  <pre><code>&lt;h:form id="allPlayers" style="text-align: center;" &gt;
                      &lt;h:selectManyCheckbox value="#{playerBean.selectedPlayers}"&gt;
                       &lt;f:selectItems value="#{playerBean.allPlayers}" var="p" itemLabel="#{p.name} #{p.position} #{p.weight}" /&gt;
                      &lt;/h:selectManyCheckbox&gt;
                      &lt;h:commandButton value="Add to Team" action="team"/&gt;
                  &lt;/h:form&gt;
              &lt;/p&gt;
              &lt;p&gt;
                  &lt;h:form id="selectedPlayers" style="text-align: center;" &gt;
                      &lt;h:dataTable value="#{playerBean.selectedPlayers}" var="players"&gt;
                          &lt;h:column&gt;
                              #{players}
                          &lt;/h:column&gt;
                          &lt;h:column&gt;
                              #{players.name}
                          &lt;/h:column&gt;
                      &lt;/h:dataTable&gt;
                      &lt;h:commandButton value="Set Team" action="team"/&gt;
                  &lt;/h:form&gt;
  </code></pre>
  
  <p><strong>Error Message</strong></p>
  
  <pre><code>javax.el.ELException: /team.xhtml: The class 'java.lang.String' does not have the property 'name'.
  at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:88)
  at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
  at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302)
  at com.sun.faces.renderkit.html_basic.TableRenderer.renderRow(TableRenderer.java:385)
  at com.sun.faces.renderkit.html_basic.TableRenderer.encodeChildren(TableRenderer.java:162)
  at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
  at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
  at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
  at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
  at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
  at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
  at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
  at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
  at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
  at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
  at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
  at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
  at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
  at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
  at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
  at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
  at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
  at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
  at java.lang.Thread.run(Thread.java:724)
  </code></pre>