GWT RequestFactory - 持续更改子实体

时间:2013-09-25 18:35:30

标签: gwt requestfactory

在我的应用程序中,我的实体都来自一个实体。我希望能够拉实体,对实体(包括其子代)进行任何更改,然后保持该实体并将更改级联 - 但我的基本测试失败。

这是我的主要实体,我正在拉动一个实例并修改:

@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 >( );
  ...

StatementSubmission类都包含本地化名称。这是我的测试场景,我拉出了我想要的Statement实体,并尝试进行修改:

...
// 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( ) );
      }
    });
  }
});

我的测试结果显示:

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]

因此,主要实体Submission的更改将被保留并正确序列化到服务器。但是对子属性Statement的更改未序列化到服务器,因此持久性不正确!

修改

我仍然无法解决问题所以我在GWT中创建了一个问题:https://code.google.com/p/google-web-toolkit/issues/detail?id=8368&q=requestfactory&colspec=ID%20Type%20Status%20Owner%20Milestone%20Summary%20Stars。该帖子包含有关序列化/反序列化对象的信息,并包括请求工厂实例发送/接收的实际有效负载。

在它离开客户端之前看起来好像有效载荷和序列化是正确的,并且一旦在服务器端收到它,就会丢失子数据。

1 个答案:

答案 0 :(得分:1)

我猜你的情况与this article

末尾的情况类似