Skip to content

Instantly share code, notes, and snippets.

@Sutil
Last active September 6, 2021 14:41
Show Gist options
  • Save Sutil/4b6dcff771ee2771cc712543291e29d5 to your computer and use it in GitHub Desktop.
Save Sutil/4b6dcff771ee2771cc712543291e29d5 to your computer and use it in GitHub Desktop.
@OneToMany unidirectional examplo usint Spring JPA.
@OneToMany unidirectional examplo usint Spring JPA.
@Entity
class Child {
@Id
private String id;
}
@Entity
class Father {
@Id
private String id;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "fatherId", nullable = false)
private List<Child> children;
}
@Service
public class FatherService {
private final FatherRepository fatherRepository;
public Father create(Father father) {
return this.fatherRepository.save(father);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment