2
votes

In my application, my entities all stem from a single entity. I would like to be able to pull the entity, make any changes to the entity (including its children), and then persist that entity and have the changes cascaded - but my basic test is failing.

This is my primary entity that I'm pulling a single instance of and modifying:

@Entity
@Component
public class Submission extends EntityAbstract implements IsSerializable
{
  ...   
  /** List of statements in this submission. */
  @OneToMany(cascade=CascadeType.ALL, mappedBy="parentSubmission")
  @NotNull
  @Valid
  private List< Statement > statements = new LinkedList< Statement >( );
  ...

The Statement and Submission classes both contain a localized name. This is my test scenario where I pull the Statement entity I want, and try to make modifications:

...
// Custom request context method for Submission:
InstanceRequest< SubmissionProxy, SubmissionProxy > persist( );
...

RequestFactory.getTest( ).get( 1L ).with( Submission.PropertiesALL ).fire( new Receiver< SubmissionProxy >( )
{
  @Override
  public void onSuccess( final SubmissionProxy immutableResponse )
  {
    final Test context = RequestFactory.getTest( );
    final SubmissionProxy submission = context.edit( immutableResponse );

    System.out.println( "received: " + submission.getLocalizedName( ) + ", " + submission.getStatements( ).get( 0 ).getLocalizedName( ) );

    // Make some modifications:
    submission.setLocalizedName( "submission-" + ( ( char )( Random.nextInt( 26 ) + 'A' ) ) );
    submission.getStatements( ).get( 0 ).setLocalizedName( "statementzzz" );

    System.out.println( "persisting: " + submission.getLocalizedName( ) + ", " + submission.getStatements( ).get( 0 ).getLocalizedName( ) );
    context.persist( ).using( submission ).with( Submission.PropertiesALL ).fire( new Receiver< SubmissionProxy >( )
    {
      @Override
      public void onSuccess( final SubmissionProxy immutableSubmission )
      {
        System.out.println( "success: " + submission.getLocalizedName( ) + ", " + immutableSubmission.getStatements( ).get( 0 ).getLocalizedName( ) );
      }
    });
  }
});

The results of my test show:

received: submissionzzz, statement-name  // Called before making modifications [client]
persisting: submission-E, statementzzz   // Called before persisting changes [client]
server: submission-E, statement-name     // Called before persisting changes [server]
success: submission-E, statement-name    // Called after persisting changes [client]

So the changes to the primary entity, Submission, are being retained and serialized properly to the server. But the changes to the child properties, Statement, are not serialized to the server so the persistence is incorrect!

EDIT:

I still haven't been able to resolve the problem so I created an issue with GWT: https://code.google.com/p/google-web-toolkit/issues/detail?id=8368&q=requestfactory&colspec=ID%20Type%20Status%20Owner%20Milestone%20Summary%20Stars. The post contains information about the serialized/deserialized objects and includes the actual payloads that the request factory instance is sending/receiving.

It looks as if the payload and serialization is correct right before it leaves client side, and as soon as it's received on the server side the child data is missing.

1

1 Answers

2
votes

I am guessing you ran in a situation like the one presented at the end of this article