title: JSF updating entity doesn't working normally
body: <p>I am trying to develop a web application using JSF 2, Hibernate and for server I am using JBoss AS 7. I have an entity Slide and a bean SliderAction. I can successfully add entities to my database and delete them but when it comes to editing an entity it causes troubles. On edit page I populate my entity and show to user for edit, and when user submits, only the last property of entity is getting updated.</p>
  
  <p>Here is Slide.class</p>
  
  <pre><code>@Entity
  public class Slide extends AbstractEntity&lt;Integer&gt;{
  
  private static final long serialVersionUID = 1L;
  
  private String title;
  private String description;
  private Image image;
  private String link;
  private Page page;
  private boolean showOnFeed;
  private boolean approved;
  private boolean cropped;
  
  public String getTitle() {
      return title;
  }
  
  public void setTitle(String title) {
      System.out.println( getId() + " = TITLE = " + title );
      this.title = title;
  }   
  
  public String getDescription() {
      return description;
  }
  
  public void setDescription(String description) {
      System.out.println( getId() + " = DESC = " + description );
      this.description = description;
  }
  
  @OneToOne
  public Image getImage() {
      return image;
  }
  
  public void setImage(Image image) {
      this.image = image;
  }
  
  public String getLink() {
      return link;
  }
  
  public void setLink(String link) {
      this.link = link;
  }
  
  @OneToOne
  public Page getPage() {
      return page;
  }
  
  public void setPage(Page page) {
      System.out.println( getId() + " = PAGE = " + page.getHeading() );
      this.page = page;
  }
  @Column(name="show_on_feed")
  public boolean isShowOnFeed() {
      return showOnFeed;
  }
  
  public void setShowOnFeed(boolean showOnFeed) {
      this.showOnFeed = showOnFeed;
  }
  
  public boolean isApproved() {
      return approved;
  }
  
  public void setApproved(boolean approved) {
      this.approved = approved;
  }
  
  public boolean isCropped() {
      return cropped;
  }
  
  public void setCropped(boolean cropped) {
      this.cropped = cropped;
  }
  }
  </code></pre>
  
  <p>SliderAction.class</p>
  
  <pre><code>@Named
  @RequestScoped
  public class SliderAction {
  
  private EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("db");
  private EntityManager entityManager;
  
  private int id;
  private int pageId;
  private Integer coordinates[] = new Integer[4];
  private Image image;    
  private Slide slide = new Slide();
  private List&lt;Slide&gt; slides = new ArrayList&lt;Slide&gt;();
  private List&lt;Slide&gt; publicSlides = new ArrayList&lt;Slide&gt;();
  private UploadedFile uploadedFile;  
  private boolean externalLink = false;
  private boolean editable = true;
  
  public String add() {
      return "add";
  }
  
  public String addSlide() {
  
      ImageAction imageAction = new ImageAction();                    
      imageAction.upload(uploadedFile, false);
  
      image = imageAction.getImage();
      slide.setImage( image );
      slide.setCropped( false );      
  
      startTransaction();
      if( !externalLink ) {
          slide.setPage(entityManager.find(Page.class, pageId));
      }
      entityManager.persist(image);
      entityManager.persist(slide);
      endTransaction();
      closeTransaction();
  
      setId(slide.getId());
  
      return "details";
  }
  
  
  public void editSlide() {
  
      System.out.println(slide);
  
      startTransaction(); 
      entityManager.merge(slide);
      endTransaction();
      closeTransaction();
  }   
  public void deleteSlide() {
  
      startTransaction();
      slide = (Slide)entityManager.find(Slide.class, id);
      entityManager.remove(slide);
      endTransaction();
      closeTransaction();
  
      slides.remove(slide);
  
      ImageAction imageAtion = new ImageAction();
      imageAtion.delete(slide.getImage().getUniqueName(), slide.getImage().getThumb());
  }
  
  public void makeEditable() {
      editable = true;
  }
  
  public void startTransaction() {
      entityManager = entityManagerFactory.createEntityManager();
      entityManager.getTransaction().begin();
  }
  
  public void endTransaction() {
      entityManager.getTransaction().commit();
  }
  
  public void closeTransaction() {
      entityManager.close();
  }
  
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  public Slide getSlide() {
      if( id != 0 ){
          startTransaction();
          slide = entityManager.find(Slide.class, id);
          endTransaction();
          closeTransaction();
      }
  
      return slide;
  }
  
  public void setSlide(Slide slide) {
      this.slide = slide;
  }
  
  public UploadedFile getUploadedFile() {
      return uploadedFile;
  }
  
  public void setUploadedFile(UploadedFile uploadedFile) {
      this.uploadedFile = uploadedFile;
  }
  
  @SuppressWarnings("unchecked")
  public List&lt;Slide&gt; getSlides() {
      startTransaction();
      slides = entityManager.createQuery("from Slide").getResultList();
      System.out.println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;SLIDES");
      endTransaction();
      closeTransaction();
  
      return slides;
  }
  
  public void setSlides(List&lt;Slide&gt; slides) {
      this.slides = slides;
  }
  
  public Integer[] getCoordinates() {
      return coordinates;
  }
  
  public void setCoordinates(Integer[] coordinates) {
      this.coordinates = coordinates;
  }
  
  public Image getImage() {
      return image;
  }
  
  public void setImage(Image image) {
      this.image = image;
  }
  
  public boolean isExternalLink() {
      return externalLink;
  }
  
  public void setExternalLink(boolean externalLink) {
      this.externalLink = externalLink;
  }
  
  @SuppressWarnings("unchecked")
  public List&lt;Slide&gt; getPublicSlides() {
      startTransaction();
      publicSlides = entityManager.createQuery("from Slide where showOnFeed = true").getResultList();
      return publicSlides;
  }
  
  public void setPublicSlides(List&lt;Slide&gt; publicSlides) {
      this.publicSlides = publicSlides;
  }
  
  public boolean isEditable() {
      return editable;
  }
  
  public void setEditable(boolean editable) {
      this.editable = editable;
  }
  
  public int getPageId() {
      return pageId;
  }
  
  public void setPageId(int pageId) {
      this.pageId = pageId;
  }
  }
  </code></pre>
  
  <p>edit page:</p>
  
  <pre><code>&lt;html&gt;
  &lt;!-- DOCTYPE specification --&gt;
      &lt;f:metadata&gt;
          &lt;f:viewParam name="id" value="#{sliderAction.id}"/&gt;
      &lt;/f:metadata&gt;
  
  &lt;ui:composition template="/view/private/administration/administrator.xhtml"&gt;
  
  &lt;ui:define name="title"&gt;#{msgs.addingSlide}&lt;/ui:define&gt;
  
  &lt;ui:define name="extra-head"&gt;
      &lt;h:outputStylesheet library="css" name="jquery.jcrop.min.css"/&gt;     
  &lt;/ui:define&gt;
  
  &lt;ui:define name="content"&gt;
  
      &lt;div class="grid_14"&gt;
  
          &lt;h4 class="page-heading"&gt;&lt;h:outputText value="#{sliderAction.slide.title} #{msgs.details}" /&gt;&lt;/h4&gt;
  
          &lt;div class="line clear"&gt;&lt;/div&gt;
  
          &lt;h:panelGroup id="details"&gt;
  
              &lt;h:form id="edit-slide"&gt;
                  &lt;h:panelGrid columns="2"&gt;
  
                      &lt;h:outputText value="#{msgs.slideTitle}" styleClass="label"/&gt;
                      &lt;h:outputText value="#{sliderAction.slide.title}" rendered="#{not sliderAction.editable}"/&gt;
                      &lt;h:inputText id="title" value="#{sliderAction.slide.title}" required="true" rendered="#{sliderAction.editable}"/&gt;
                      &lt;p&gt;&lt;/p&gt;&lt;h:message for="title" errorClass="error"/&gt;
  
                      &lt;h:outputText value="#{msgs.description}" styleClass="label"/&gt;
                      &lt;h:outputText value="#{sliderAction.edidSlide.description}" rendered="#{not sliderAction.editable}"/&gt;
                      &lt;h:inputTextarea id="description" value="#{sliderAction.slide.description}" required="true" rendered="#{sliderAction.editable}"/&gt;                                                               
                      &lt;p&gt;&lt;/p&gt;&lt;h:message for="description" errorClass="error"/&gt;
  
                      &lt;h:outputText value="#{msgs.page}" styleClass="label" /&gt;
                      &lt;h:link outcome="notset" rendered="#{not sliderAction.editable}"&gt;
                          &lt;h:outputText value="#{sliderAction.slide.page.heading}"/&gt;
                          &lt;f:param name="id" value="#{sliderAction.slide.page.id}" /&gt;
                      &lt;/h:link&gt;
                      &lt;h:selectOneMenu id="page" value="#{sliderAction.pageId}" required="true" rendered="#{sliderAction.editable}"&gt;
                          &lt;f:selectItems value="#{pageAction.pages}" var="page" itemLabel="#{page.heading}" itemValue="#{page.id}"/&gt;
                      &lt;/h:selectOneMenu&gt;                  
                      &lt;p&gt;&lt;/p&gt;&lt;h:message for="page" errorClass="error"/&gt;               
  
                      &lt;p&gt;&lt;/p&gt;
                      &lt;h:commandButton action="#{sliderAction.makeEditable}" value="#{msgs.edit}" styleClass="button" rendered="#{not sliderAction.editable}"&gt;
                          &lt;f:ajax render="@form" execute="@this" /&gt;
                      &lt;/h:commandButton&gt;
                      &lt;h:commandButton action="#{sliderAction.editSlide}" value="#{msgs.saveChanges}" styleClass="button" rendered="#{sliderAction.editable}"&gt;
                          &lt;f:ajax render="@form" execute="@form" /&gt;
                      &lt;/h:commandButton&gt;
  
                      &lt;h:message for="edit-slide"/&gt;
  
                  &lt;/h:panelGrid&gt;
              &lt;/h:form&gt;
  
          &lt;/h:panelGroup&gt;
  
      &lt;/div&gt;
  
  &lt;/ui:define&gt;
  </code></pre>
  
  <p></p>
  
  <p></p>
  
  <p>Here when user submits, only the slide.description is updated. What can cause such promblems? If code is not enough just let me know.</p>