I have a bidirectional one-to-many relationship. I'm trying to persist it like in this doc:
Parent p = (Parent) session.load(Parent.class, pid);
Child c = new Child();
c.setParent(p);
p.getChildren().add(c);
session.save(c);
session.flush();
Is the flush()
required there? What exactly does it do? I know what it does, but I discovered it costs me 100 ms and I would really like to avoid it if possible.
When session.load()
or even session.refresh()
is called and I hadn't flushed, will it include the new Child
in the collection?