在我的应用程序中,我的实体都源自一个实体。我希望能够拉动实体,对实体(包括其子实体)进行任何更改,然后保留该实体并将更改级联 - 但我的基本测试失败了。
这是我要提取和修改的单个实例的主要实体:
@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 >( );
...
和Statement
类Submission
都包含本地化名称。这是我的测试场景,我拉出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。该帖子包含有关序列化/反序列化对象的信息,并包括请求工厂实例正在发送/接收的实际有效负载。
看起来负载和序列化在它离开客户端之前是正确的,并且一旦在服务器端接收到它,子数据就会丢失。