Skip to content

Instantly share code, notes, and snippets.

@renanpalmeira
Last active August 9, 2018 21:29
Show Gist options
  • Save renanpalmeira/706aa430789c288c7b1ac5d676cce5c0 to your computer and use it in GitHub Desktop.
Save renanpalmeira/706aa430789c288c7b1ac5d676cce5c0 to your computer and use it in GitHub Desktop.
Model model = repo.findById(22L);
ModelAddress modelAddress = new ModelAddress();
modelAddress.setIdModel(model.setIdModel());
Optional<InstitutionAccountDocument> addressResponse = repoAddress.save(modelAddress);
// normal here
addressResponse.ifPresent(modelAddressResponse -> model.setModelAddress(singleList(modelAddressResponse)));
ModelEmail modelEmail = new ModelEmail();
modelEmail.setIdModel(model.setIdModel());
Optional<InstitutionAccountDocument> emailResponse = repoEmail.save(modelEmail); // here is a evil/error
emailResponse.ifPresent(modelEmailResponse -> model.setModelEmail(singleList(modelEmailResponse)));
class Model {
@OneToMany
@NotFound(action = NotFoundAction.IGNORE)
@JoinTable(
name = "model_address",
joinColumns = @JoinColumn(name = "idModel"),
inverseJoinColumns = @JoinColumn(name = "idModelAddress")
)
private List<ModelAddress> modelAddress;
@OneToMany
@NotFound(action = NotFoundAction.IGNORE)
@JoinTable(
name = "model_email",
joinColumns = @JoinColumn(name = "idModel"),
inverseJoinColumns = @JoinColumn(name = "idModelEmail")
)
private List<ModelEmail> modelEmail;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment