I have two entities.
@Entity
public class Recipe {
@Id
private Long id;
private List<Step> steps;
}
@Entity
public class Step {
@Id
private Long id;
private String instruction;
}
And the following Clound Endpoint
@ApiMethod(
name = "insert",
path = "recipe",
httpMethod = ApiMethod.HttpMethod.POST)
public Recipe insert(Recipe recipe) {
ofy().save().entities(recipe.getSteps()).now(); //superfluous?
ofy().save().entity(recipe).now();
logger.info("Created Recipe with ID: " + recipe.getId());
return ofy().load().entity(recipe).now();
}
I'm wondering how do I skip the step where I have to save the emebedded entity first. The Id of neither entity is set. I want objectify to automatically create those. But if don't save the embedded entity I get an exception.
com.googlecode.objectify.SaveException: Error saving com.devmoon.meadule.backend.entities.Recipe@59e4ff19: You cannot create a Key for an object with a null @Id. Object was com.devmoon.meadule.backend.entities.Step@589a3afb
Since my object structure will get a lot more complex, I need to find a way to skip this manual step.