是否可以在方法中创建子代的引用,但将子实体保留在其他方法中?
现在,我首先创建引用,然后使用相同的方法将孩子持久化。仅在完成此操作后,父级才会保留。如果在保存父实体期间发生DatastoreTimeoutException,ConcurrentModificationException或DatastoreFailureException,则我将子实体保留在数据存储中,这毫无用处。
@Entity
@Index
public class parentEntity
{
@Id
private String uniqueIdentifier;
private String name = new String();
@Load
private LinkedList <Ref <childEntity>> refToChild = new LinkedList <Ref <childEntity>>();
}
@Entity
@Index
public class childEntity
{
@Id
private String uniqueIdentifier;
private String address = new String();
@Load
@Parent
public Ref <parentEntity> refToParent;
}
This method first creates the reference parent has with child and then persists the entity(child)
public static void createRefAndSaveChildEntity()
{
Ref.create( key ) ;//creates the reference with child
ofy().save().entity( childEntity ).now();
}
我只想在父母(涉及孩子)被坚持之后才坚持孩子。