4 Replies Latest reply on Oct 10, 2009 10:26 PM by first last

    EntityHome.refresh() does not reload a field (which is a collection)

    first last Newbie

      Hey y'all,

      I am struggling with the following persistence issue for a while now:

      I have a Client entity that has a collection of Representatives:

      public class Client implements Serializable {
              private List<Representative> representatives =
                       new ArrayList<Representative>();
              @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE},
           public List<Representative> getRepresentatives() {
                return representatives;
           public void setRepresentatives(List<Representative> representatives) {
                this.representatives = representatives;

      The Representative class is nothing special:

      public class Representative implements Serializable {
              private Client client;
           public Client getClient() {
                return client;
           public void setClient(Client client) {
                this.client = client;

      For controlling a Client entity, I have a ClientHome class, and in it - a method to refresh the Client from the DB (if the user clicks an 'undo' button while filling out the form) :

      public class ClientHome extends EntityHome<Client>
           public void undo() {

      Now, I have a ClientDetails.xhtml page that shows details of the client (duh) including its list of representatives. (The page has a page-parameter for the client Id, as is the base use case of using EntityHome):

      <rich:dataTable id="repTable"
                      <h:outputText value="#{_rep.name}" />

      You can also click on a Representative and edit his details, the entire thing runs in a long-running conversation which has flush-mode="manual", and it works great, EXCEPT that when you click the 'undo' button:

      <h:commandButton id="undo"
                     immediate="true" />

      Whatever changes were made to the client's representatives still appear (!) The 'representatives' field of the Client entity is not being properly reloaded from the DB.
      That is so even though the query does happen and get logged out:

      21:50:44,531 INFO  [STDOUT] Hibernate: 
              client0_.id as id37_0_,
              client0_.name as name37_0_,
              Client client0_ 
      21:50:44,609 INFO  [STDOUT] Hibernate: 
              representa0_.client_id as client14_1_,
              representa0_.id as id1_,
              representa0_.id as id43_0_,
              representa0_.name as name43_0_,
              Representative representa0_ 

      Any idea why the dirty Representative remain intact in the Persistence Context, and are not replaced by they second query's results ??

      Thanks for any info!