gwtrequestfactoryopen-session-in-view

GWT RequestFactory with Set sub-collections


I have a little problem with RequestFactory regarding persistence of children collections in the shape of Set . I am using 2.5 with , and Hibernate4/Spring3 at the backend. I am using the filter by Spring so that collections can be persisted after findByID in the save method of my DAO. My problem is everything seems to work ok when children collections are based on List , but when they are based on Set , not all of the items from the client reach the server aparently.

My code looks like this:

-The root entity IndicationTemplate:

@Entity
@Table (name = "vdasIndicationTemplate")
@org.hibernate.annotations.Table ( appliesTo = "vdasIndicationTemplate", indexes = 
               {@Index (name = "xieIndicationTemplateCreateUser", columnNames= {"createUserID"}),
               @Index (name = "xieIndicationTemplateModifyUser", columnNames= {"modifyUserID"})})
public class IndicationTemplate extends AbstractEditable <Integer> implements IEntity <Integer>, IDateable, IDescriptable {
//...
   private Set <ProposalTemplate> proposalTemplates = null;
//...
   @OneToMany (fetch = FetchType.LAZY, mappedBy = "indicationTemplate"
         , cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.DETACH})
   public Set <ProposalTemplate> getProposalTemplates () {
      return proposalTemplates;
   }
   public void setProposalTemplates (Set <ProposalTemplate> proposalTemplates) {
      this.proposalTemplates = proposalTemplates;
   }
//...
}

-The child entity ProposalTemplate of course has the opposite ManyToOne mapping and has 3 sub-collections as well of the same sort with 3 different entities.

-Client-side proxy for root entity:

@ProxyFor (value = IndicationTemplate.class, locator = PersistenceEntityLocator.class)
public interface IIndicationTemplateProxy extends IEntityProxy, IDeletableProxy, IDescriptableProxy {
//....
   Set <IProposalTemplateProxy> getProposalTemplates ();
   void setProposalTemplates (Set <IProposalTemplateProxy> proposalTemplateProxy);
}

-On the client, i render the attributes of root entity and also the list of children entity. Then the user can update them, and the changes are stored back into the collection like this:

   Set <IProposalTemplateProxy> newList = getElementsFromUiSomehow (); //these elements can be new or just the old ones with some changes
   indicationTemplate.getProposalTemplates ().clear ();
   indicationTemplate.getProposalTemplates ().addAll (newList);

-And then at some point:

   requestContext.saveIndicationTemplate ((IIndicationTemplateProxy) entityProxy)
                                          .fire (new Receiver <IIndicationTemplateProxy> () 

-The RequestContext looks something like:

@Service (value = TemplateService.class, locator = SpringServiceLocator.class)
public interface ITemplateRequestContext extends RequestContext {
   /** saves (creates or updates) one given indication template */
   Request <IIndicationTemplateProxy> saveIndicationTemplate (IIndicationTemplateProxy indicationTemplate);
//....
}

The problem is only 1 child entity is added per request to the collection server-side. For example, indicationTemplate has 2 proposalTemplates, and i add 4 more, then on the server-side saveIndicationTemplate the entity contains only 3 instead of 6. If happens no matter how many entities i have previously and how many i add, i only get 1 more than before on the server. I did check the proxy object right before firing the requestContext method and it is fully loaded, with all of its children. And finally the weirdest thing is, if i replace Set per List (and all subsequent changes), everything works sweet!

May there be any problem why RF fails to transfer all the changes to the server when using Sets instead of Lists?? Btw, i do prefer Sets in this case, so that is why i am asking.

Anyone?

Thanks for helping!


Solution

  • I assume you are hitting this error. It is a known gwt bug which is still unfixed.

    https://code.google.com/p/google-web-toolkit/issues/detail?id=6354&q=set&colspec=ID%20Type%20Status%20Owner%20Milestone%20Summary%20Stars

    try to use list instead of set and it should be fine.