How to save parent entity first with reference to child where child is not persisted yet (Objectify)?keys and unique rows in appengine datastoreCreate the perfect JPA entityInserting two enties in a transaction & getting 'Cannot operate on different entity groups in a transaction' ErrorRef<?> value has not been initializedOneToMany: reference to parent entity is not up to date in child after parent was updatedObjectify @Parent annotation vs RefCascading a Child entity persist operation to its Parent entityHow to cascade parent entity when persisting child in bidirectionalSpring Data Rest - can not update (PATCH) a list of child entities that have a reference to another entityPersist entity having already exsisting child

is it possible to change a material depending on whether it is intersecting with another object?

How did vāti-s become vātēs?

When does order matter in probability?

When did computers stop checking memory on boot?

Short story: Interstellar inspector senses "off" nature of planet hiding aggressive culture

Is a MySQL database a viable alternative to LDAP?

Python implementation of atoi

Problem with listing a directory to grep

Word for something that used to be popular but not anymore

Quick Shikaku Puzzle: Stars and Stripes

Is there a way to deal with desistance in a off-chain game?

Does the word voltage exist in academic engineering?

How to convert P2O5 concentration to H3PO4 concentration?

Automatically end list item with proper punctuation (semicolon, period)

Capacitors with same voltage, same capacitance, same temp, different diameter?

Was Robin Hood's point of view ethically sound?

antimatter annihilation in stars

What is the difference between tl_to_str:V and tl_to_str:N?

How can I return only the number of paired values in array?

The Green Glass Door, Revisited

What happens when a file that is 100% paged in to the page cache gets modified by another process

2 load centers under 1 meter: do you need bonding and main breakers at both?

Galilean transformation vs simple translation

Why can't some airports handle heavy aircraft while others do it easily (same runway length)?



How to save parent entity first with reference to child where child is not persisted yet (Objectify)?


keys and unique rows in appengine datastoreCreate the perfect JPA entityInserting two enties in a transaction & getting 'Cannot operate on different entity groups in a transaction' ErrorRef<?> value has not been initializedOneToMany: reference to parent entity is not up to date in child after parent was updatedObjectify @Parent annotation vs RefCascading a Child entity persist operation to its Parent entityHow to cascade parent entity when persisting child in bidirectionalSpring Data Rest - can not update (PATCH) a list of child entities that have a reference to another entityPersist entity having already exsisting child






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Is there a way to create the reference of the child in a method but persist the child entity in a different method?



Right now, I am creating the reference first and then persisting the child in the same method. Only after this is being done, the parent is persisted. If DatastoreTimeoutException, ConcurrentModificationException, or DatastoreFailureException occurs during saving parent entity, I am left with child entity persisted in datastore which is of no use.



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



I want to persist the child only after the parent(with reference to child) is being persisted.










share|improve this question
























  • why would you want to link to an object that doesn't exist yet? what if there's a problem persisting the child entity?

    – Stultuske
    Mar 28 at 7:18











  • Given that you are using a parent-child relationship, you should be able to use an ancestor query to retrieve the children instead of keeping an explicit reference to the child entities in the parent entity.

    – Jim Morrison
    Mar 28 at 16:49











  • @Stultuske yeah, coming to think of it, a problem could arise when persisting the child.

    – Hanok Jacob
    Apr 5 at 13:52











  • @JimMorrison, yeah for querying i could, but how to do while saving?

    – Hanok Jacob
    Apr 5 at 13:53











  • What I was saying is that you don't need to keep an explicit reference because you have an implicit reference through ancestor queries.

    – Jim Morrison
    Apr 6 at 16:04

















0















Is there a way to create the reference of the child in a method but persist the child entity in a different method?



Right now, I am creating the reference first and then persisting the child in the same method. Only after this is being done, the parent is persisted. If DatastoreTimeoutException, ConcurrentModificationException, or DatastoreFailureException occurs during saving parent entity, I am left with child entity persisted in datastore which is of no use.



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



I want to persist the child only after the parent(with reference to child) is being persisted.










share|improve this question
























  • why would you want to link to an object that doesn't exist yet? what if there's a problem persisting the child entity?

    – Stultuske
    Mar 28 at 7:18











  • Given that you are using a parent-child relationship, you should be able to use an ancestor query to retrieve the children instead of keeping an explicit reference to the child entities in the parent entity.

    – Jim Morrison
    Mar 28 at 16:49











  • @Stultuske yeah, coming to think of it, a problem could arise when persisting the child.

    – Hanok Jacob
    Apr 5 at 13:52











  • @JimMorrison, yeah for querying i could, but how to do while saving?

    – Hanok Jacob
    Apr 5 at 13:53











  • What I was saying is that you don't need to keep an explicit reference because you have an implicit reference through ancestor queries.

    – Jim Morrison
    Apr 6 at 16:04













0












0








0








Is there a way to create the reference of the child in a method but persist the child entity in a different method?



Right now, I am creating the reference first and then persisting the child in the same method. Only after this is being done, the parent is persisted. If DatastoreTimeoutException, ConcurrentModificationException, or DatastoreFailureException occurs during saving parent entity, I am left with child entity persisted in datastore which is of no use.



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



I want to persist the child only after the parent(with reference to child) is being persisted.










share|improve this question














Is there a way to create the reference of the child in a method but persist the child entity in a different method?



Right now, I am creating the reference first and then persisting the child in the same method. Only after this is being done, the parent is persisted. If DatastoreTimeoutException, ConcurrentModificationException, or DatastoreFailureException occurs during saving parent entity, I am left with child entity persisted in datastore which is of no use.



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



I want to persist the child only after the parent(with reference to child) is being persisted.







java google-cloud-datastore objectify






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 7:17









Hanok JacobHanok Jacob

63 bronze badges




63 bronze badges















  • why would you want to link to an object that doesn't exist yet? what if there's a problem persisting the child entity?

    – Stultuske
    Mar 28 at 7:18











  • Given that you are using a parent-child relationship, you should be able to use an ancestor query to retrieve the children instead of keeping an explicit reference to the child entities in the parent entity.

    – Jim Morrison
    Mar 28 at 16:49











  • @Stultuske yeah, coming to think of it, a problem could arise when persisting the child.

    – Hanok Jacob
    Apr 5 at 13:52











  • @JimMorrison, yeah for querying i could, but how to do while saving?

    – Hanok Jacob
    Apr 5 at 13:53











  • What I was saying is that you don't need to keep an explicit reference because you have an implicit reference through ancestor queries.

    – Jim Morrison
    Apr 6 at 16:04

















  • why would you want to link to an object that doesn't exist yet? what if there's a problem persisting the child entity?

    – Stultuske
    Mar 28 at 7:18











  • Given that you are using a parent-child relationship, you should be able to use an ancestor query to retrieve the children instead of keeping an explicit reference to the child entities in the parent entity.

    – Jim Morrison
    Mar 28 at 16:49











  • @Stultuske yeah, coming to think of it, a problem could arise when persisting the child.

    – Hanok Jacob
    Apr 5 at 13:52











  • @JimMorrison, yeah for querying i could, but how to do while saving?

    – Hanok Jacob
    Apr 5 at 13:53











  • What I was saying is that you don't need to keep an explicit reference because you have an implicit reference through ancestor queries.

    – Jim Morrison
    Apr 6 at 16:04
















why would you want to link to an object that doesn't exist yet? what if there's a problem persisting the child entity?

– Stultuske
Mar 28 at 7:18





why would you want to link to an object that doesn't exist yet? what if there's a problem persisting the child entity?

– Stultuske
Mar 28 at 7:18













Given that you are using a parent-child relationship, you should be able to use an ancestor query to retrieve the children instead of keeping an explicit reference to the child entities in the parent entity.

– Jim Morrison
Mar 28 at 16:49





Given that you are using a parent-child relationship, you should be able to use an ancestor query to retrieve the children instead of keeping an explicit reference to the child entities in the parent entity.

– Jim Morrison
Mar 28 at 16:49













@Stultuske yeah, coming to think of it, a problem could arise when persisting the child.

– Hanok Jacob
Apr 5 at 13:52





@Stultuske yeah, coming to think of it, a problem could arise when persisting the child.

– Hanok Jacob
Apr 5 at 13:52













@JimMorrison, yeah for querying i could, but how to do while saving?

– Hanok Jacob
Apr 5 at 13:53





@JimMorrison, yeah for querying i could, but how to do while saving?

– Hanok Jacob
Apr 5 at 13:53













What I was saying is that you don't need to keep an explicit reference because you have an implicit reference through ancestor queries.

– Jim Morrison
Apr 6 at 16:04





What I was saying is that you don't need to keep an explicit reference because you have an implicit reference through ancestor queries.

– Jim Morrison
Apr 6 at 16:04












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392038%2fhow-to-save-parent-entity-first-with-reference-to-child-where-child-is-not-persi%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392038%2fhow-to-save-parent-entity-first-with-reference-to-child-where-child-is-not-persi%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해