Consider I have 2 entity
@Entity(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
@OneToMany(cascade = CascadeType.ALL)
public List<Child> children = new ArrayList<>();
}
and
@Entity
class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
@ManyToOne
public Parent parent;
}
how can I create Child instance with parentId
without call findById(Long parentId)
i.e.
Child createChild(parentId) {
Child child = new Child();
child.parent = //parent.findById(parentId); I don't wanna go to database
//for nothing if in this spot anyway will be parentId in database
return child;
}
I thought it can be done with quare but hql don't have
INSERT .... VALUE ..
, so I'm here, appreciate any help.
If it's don't have any sense due to architecture, please explain, it's be a great help.