2 Replies Latest reply on Apr 14, 2010 11:31 PM by Hai-Yun Du

    Unexpected update of database with entities and rich:suggestionbox

    Hai-Yun Du Newbie
      I have a rich:datatable bound to a list property within an entity (personHome.personCourses returns a list of personCourse entities). In the datatable columns, there is a rich:suggestionbox bound to an input which is bound to the personCourse.course.name. When I change the value of the suggestionbox, the database gets updated immediately without my explicitly calling update on the entity. What could be causing this to happen?

      <rich:dataTable var="_personCourse" value="#{personHome.personCourses}">
           
        <rich:columnGroup>
          <rich:column>
            <h:inputText id="courseInput" value="#{_personCourse.course.name}" />
            <h:graphicImage value="/img/dropdown.png" onclick="#{rich:component('courseSuggestion')}.callSuggestion(true)"/>
            <rich:suggestionbox id="courseSuggestion" for="courseInput" fetchValue="#{_course.name}" var="_course" suggestionAction="#{courseLookup.lookup}">
              <a4j:support event="onselect">
                <f:setPropertyActionListener target="#{_personCourse.course}" value="#{_course}"/>
              </a4j:support>
              <h:column>
                <h:outputText value="#{_course.name}"/>
              </h:column>
            </rich:suggestionbox>
          </rich:column>
        </rich:columnGroup>

      </rich:dataTable>
        • 1. Re: Unexpected update of database with entities and rich:suggestionbox
          Gabor Jakab Newbie

          It seems your managed Entities are updated during session synchronization with your Ajax request. Actualy, why do you need this "onselect" if you only want to evaluate changes only after call to your update? You can use some detached list of objects for your GUI layer which you synchorize with your entities in update or use Hibernate's Manual Flush mode for this conversation. Also try to use eventsQueue="" and requestDelay="" attributes for your suggestionBox with some sensible values...


          hope that helps...

          • 2. Re: Unexpected update of database with entities and rich:suggestionbox
            Hai-Yun Du Newbie

            Thanks. It was the automatic flushing that caused the immediate updates. I have set it to manual flush mode.


            Another problem with the above suggestionbox is that it is also updating Course.name. It should only be setting PersonCourse.course




            @Entity
            public class PersonCourse {
                 private int id;
                 private Course course;
            ...
            }
            
            @Entity
            public class Course {
                 private int id;
                 private String name;
            }